3 namespace Drupal\views\Plugin\views\display;
5 use Drupal\views\ViewExecutable;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\Core\Session\AccountInterface;
10 * @defgroup views_display_plugins Views display plugins
12 * Plugins to handle the overall display of views.
14 * Display plugins are responsible for controlling where a view is rendered;
15 * that is, how it is exposed to other parts of Drupal. 'Page' and 'block' are
16 * the most commonly used display plugins. Each view also has a 'master' (or
17 * 'default') display that includes information shared between all its
18 * displays (see \Drupal\views\Plugin\views\display\DefaultDisplay).
20 * Display plugins extend \Drupal\views\Plugin\views\display\DisplayPluginBase.
21 * They must be annotated with \Drupal\views\Annotation\ViewsDisplay
22 * annotation, and they must be in namespace directory Plugin\views\display.
24 * @ingroup views_plugins
27 * @see views_display_extender_plugins
31 * Provides an interface for Views display plugins.
33 interface DisplayPluginInterface {
36 * Initializes the display plugin.
38 * @param \Drupal\views\ViewExecutable $view
39 * The views executable.
40 * @param array $display
41 * The display that will be populated and attached to the view.
42 * @param array $options
43 * (optional) The options for the display plugin. Defaults to NULL.
45 public function initDisplay(ViewExecutable $view, array &$display, array &$options = NULL);
48 * Destroys the display's components and the display itself.
50 public function destroy();
53 * Determines if this display is the 'default' display.
55 * 'Default' display contains fallback settings.
57 public function isDefaultDisplay();
60 * Determines if this display uses exposed filters.
62 public function usesExposed();
65 * Determines if this display should display the exposed filters widgets.
67 * Regardless of what this function
68 * returns, exposed filters will not be used nor
69 * displayed unless usesExposed() returns TRUE.
71 public function displaysExposed();
74 * Whether the display allows the use of AJAX or not.
78 public function usesAJAX();
81 * Whether the display is actually using AJAX or not.
85 public function ajaxEnabled();
88 * Whether the display is enabled.
91 * Returns TRUE if the display is marked as enabled, else FALSE.
93 public function isEnabled();
96 * Whether the display allows the use of a pager or not.
100 public function usesPager();
103 * Whether the display is using a pager or not.
107 public function isPagerEnabled();
110 * Whether the display allows the use of a 'more' link or not.
114 public function usesMore();
117 * Whether the display is using the 'more' link or not.
121 public function isMoreEnabled();
124 * Does the display have groupby enabled?
126 public function useGroupBy();
129 * Should the enabled display more link be shown when no more items?
131 public function useMoreAlways();
134 * Does the display have custom link text?
136 public function useMoreText();
139 * Determines whether this display can use attachments.
143 public function acceptAttachments();
146 * Returns whether the display can use attachments.
150 public function usesAttachments();
153 * Returns whether the display can use areas.
156 * TRUE if the display can use areas, or FALSE otherwise.
158 public function usesAreas();
161 * Allows displays to attach to other views.
163 * @param \Drupal\views\ViewExecutable $view
164 * The views executable.
165 * @param string $display_id
166 * The display to attach to.
167 * @param array $build
168 * The parent view render array.
170 public function attachTo(ViewExecutable $view, $display_id, array &$build);
173 * Lists the 'defaultable' sections and what items each section contains.
175 public function defaultableSections($section = NULL);
178 * Checks to see if the display has a 'path' field.
180 * This is a pure function and not just a setting on the definition
181 * because some displays (such as a panel pane) may have a path based
182 * upon configuration.
184 * By default, displays do not have a path.
186 public function hasPath();
189 * Checks to see if the display has some need to link to another display.
191 * For the most part, displays without a path will use a link display.
192 * However, sometimes displays that have a path might also need to link to
193 * another display. This is true for feeds.
195 public function usesLinkDisplay();
198 * Checks to see if the display can put the exposed form in a block.
200 * By default, displays that do not have a path cannot disconnect
201 * the exposed form and put it in a block, because the form has no
202 * place to go and Views really wants the forms to go to a specific
205 public function usesExposedFormInBlock();
208 * Find out all displays which are attached to this display.
210 * The method is just using the pure storage object to avoid loading of the
211 * sub displays which would kill lazy loading.
213 public function getAttachedDisplays();
216 * Returns the ID of the display to use when making links.
218 public function getLinkDisplay();
221 * Returns the base path to use for this display.
223 * This can be overridden for displays that do strange things
226 public function getPath();
229 * Points to the display which can be linked by this display.
231 * If the display has route information, the display itself is returned.
232 * Otherwise, the configured linked display is returned. For example, if a
233 * block display links to a page display, the page display will be returned
236 * @return \Drupal\views\Plugin\views\display\DisplayRouterInterface|null
238 public function getRoutedDisplay();
241 * Returns a URL to $this display or its configured linked display.
243 * @return \Drupal\Core\Url|null
245 public function getUrl();
248 * Determines if an option is set to use the default or current display.
251 * TRUE for the default display.
253 public function isDefaulted($option);
256 * Gets an option, from this display or the default display.
258 public function getOption($option);
261 * Determines if the display's style uses fields.
265 public function usesFields();
268 * Get the instance of a plugin, for example style or row.
270 * @param string $type
271 * The type of the plugin.
273 * @return \Drupal\views\Plugin\views\ViewsPluginInterface
275 public function getPlugin($type);
278 * Get the handler object for a single handler.
280 public function getHandler($type, $id);
283 * Get a full array of handlers for $type. This caches them.
285 * @return \Drupal\views\Plugin\views\ViewsHandlerInterface[]
287 public function getHandlers($type);
290 * Retrieves a list of fields for the current display.
292 * This also takes into account any associated relationships, if they exist.
294 * @param bool $groupable_only
295 * (optional) TRUE to only return an array of field labels from handlers
296 * that support the useStringGroupBy method, defaults to FALSE.
299 * An array of applicable field options, keyed by ID.
301 public function getFieldLabels($groupable_only = FALSE);
304 * Sets an option, on this display or the default display.
306 public function setOption($option, $value);
309 * Set an option and force it to be an override.
311 public function overrideOption($option, $value);
314 * Returns a link to a section of a form.
316 * Because forms may be split up into sections, this provides an easy URL
317 * to exactly the right section. Don't override this.
319 public function optionLink($text, $section, $class = '', $title = '');
322 * Returns to tokens for arguments.
324 * This function is similar to views_handler_field::getRenderTokens()
325 * but without fields tokens.
327 public function getArgumentsTokens();
330 * Provides the default summary for options in the views UI.
332 * This output is returned as an array.
334 public function optionsSummary(&$categories, &$options);
337 * Provides the default form for setting options.
339 public function buildOptionsForm(&$form, FormStateInterface $form_state);
342 * Validates the options form.
344 public function validateOptionsForm(&$form, FormStateInterface $form_state);
347 * Performs any necessary changes to the form values prior to storage.
349 * There is no need for this function to actually store the data.
351 public function submitOptionsForm(&$form, FormStateInterface $form_state);
354 * If override/revert was clicked, perform the proper toggle.
356 public function optionsOverride($form, FormStateInterface $form_state);
359 * Flip the override setting for the given section.
361 * @param string $section
362 * Which option should be marked as overridden, for example "filters".
363 * @param bool $new_state
364 * Select the new state of the option:
365 * - TRUE: Revert new state option to default.
366 * - FALSE: Mark it as overridden.
368 public function setOverride($section, $new_state = NULL);
371 * Injects anything into the query that the display handler needs.
373 public function query();
376 * Does nothing (obsolete function).
378 * @todo This function no longer seems to be used.
380 public function renderFilters();
383 * Checks to see if the display plugins support pager rendering.
385 public function renderPager();
388 * Renders the 'more' link.
390 public function renderMoreLink();
393 * Renders this display.
395 public function render();
398 * #pre_render callback for view display rendering.
400 * @see self::render()
402 * @param array $element
403 * The element to #pre_render
406 * The processed element.
408 public function elementPreRender(array $element);
411 * Renders one of the available areas.
413 * @param string $area
414 * Identifier of the specific area to render.
416 * (optional) Indicator whether or not the view result is empty. Defaults to
420 * A render array for the given area.
422 public function renderArea($area, $empty = FALSE);
425 * Determines if the user has access to this display of the view.
427 public function access(AccountInterface $account = NULL);
430 * Sets up any variables on the view prior to execution.
432 * These are separated from execute because they are extremely common
433 * and unlikely to be overridden on an individual display.
435 public function preExecute();
438 * Calculates the display's cache metadata by inspecting each handler/plugin.
440 * @return \Drupal\Core\Cache\CacheableMetadata
441 * The cache metadata.
443 public function calculateCacheMetadata();
446 * Gets the cache metadata.
448 * @return \Drupal\Core\Cache\CacheableMetadata
449 * The cache metadata.
451 public function getCacheMetadata();
454 * Executes the view and returns data in the format required.
456 * The base class cannot be executed.
458 public function execute();
462 * Builds a basic render array which can be properly render cached.
464 * In order to be rendered cached, it includes cache keys as well as the data
465 * required to load the view on cache misses.
467 * @param string $view_id
469 * @param string $display_id
472 * (optional) The view arguments.
475 * The view render array.
477 public static function buildBasicRenderable($view_id, $display_id, array $args = []);
480 * Builds a renderable array of the view.
482 * Note: This does not yet contain the executed view, but just the loaded view
486 * (optional) Arguments of the view.
488 * (optional) Specify FALSE in order to opt out of render caching.
491 * The render array of a view.
493 public function buildRenderable(array $args = [], $cache = TRUE);
496 * Renders the display for the purposes of a live preview.
498 * Also might be used for some other AJAXy reason.
500 public function preview();
503 * Returns the display type that this display requires.
505 * This can be used for filtering views plugins. E.g. if a plugin category of
506 * 'foo' is specified, only plugins with no 'types' declared or 'types'
507 * containing 'foo'. If you have a type of bar, this plugin will not be used.
508 * This is applicable for style, row, access, cache, and exposed_form plugins.
511 * The required display type. Defaults to 'normal'.
513 * @see \Drupal\views\Views::fetchPluginNames()
515 public function getType();
518 * Make sure the display and all associated handlers are valid.
521 * Empty array if the display is valid; an array of error strings if it is
524 public function validate();
527 * Reacts on adding a display.
529 * @see \Drupal\views\Entity\View::newDisplay()
531 public function newDisplay();
534 * Reacts on deleting a display.
536 public function remove();
539 * Checks if the provided identifier is unique.
542 * The id of the handler which is checked.
543 * @param string $identifier
544 * The actual get identifier configured in the exposed settings.
547 * Returns whether the identifier is unique on all handlers.
549 public function isIdentifierUnique($id, $identifier);
552 * Is the output of the view empty.
554 * If a view has no result and neither the empty, nor the footer nor the header
555 * does show anything return FALSE.
558 * Returns TRUE if the output is empty, else FALSE.
560 public function outputIsEmpty();
563 * Provides the block system with any exposed widget blocks for this display.
565 public function getSpecialBlocks();
568 * Renders the exposed form as block.
570 * @return string|null
571 * The rendered exposed form as string or NULL otherwise.
573 public function viewExposedFormBlocks();
576 * Provides help text for the arguments.
579 * Returns an array which contains text for the argument fieldset:
580 * - filter value present: The title of the fieldset in the argument
581 * where you can configure what should be done with a given argument.
582 * - filter value not present: The title of the fieldset in the argument
583 * where you can configure what should be done if the argument does not
585 * - description: A description about how arguments are passed
586 * to the display. For example blocks can't get arguments from url.
588 public function getArgumentText();
591 * Provides help text for pagers.
594 * Returns an array which contains text for the items_per_page form
596 * - items per page title: The title text for the items_per_page form
598 * - items per page description: The description text for the
599 * items_per_page form element.
601 public function getPagerText();
604 * Merges default values for all plugin types.
606 public function mergeDefaults();
609 * Gets the display extenders.
611 * @return \Drupal\views\Plugin\views\display_extender\DisplayExtenderPluginBase[]
613 public function getExtenders();