Views plugins

Views plugins are objects that are used to build and render the view. Plugins are registered by extending one of the Views base plugin classes and defining settings in the plugin annotation.

Views has the following types of plugins:

  • Access: Access plugins are responsible for controlling access to the view. Views includes plugins for checking user roles and individual permissions. Access plugins extend \Drupal\views\Plugin\views\access\AccessPluginBase.
  • Argument default: Argument default plugins allow pluggable ways of providing default values for contextual filters. This is useful for blocks and other display types lacking a natural argument input. Examples are plugins to extract node and user IDs from the URL. Argument default plugins extend \Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase.
  • Argument validator: Validator plugins can ensure arguments are valid, and even do transformations on the arguments. They can also provide replacement patterns for the view title. For example, the 'content' validator verifies verifies that the argument value corresponds to a node, loads that node and provides the node title as a replacement pattern. Argument validator plugins extend \Drupal\views\Plugin\views\argument_validator\ArgumentValidatorPluginBase.
  • Cache: Cache plugins control the storage and loading of caches. Currently they can do both result and render caching. It might also be possible to cache the generated query. Cache plugins extend \Drupal\views\Plugin\views\cache\CachePluginBase.
  • Display: Display plugins are responsible for controlling where a View is rendered; that is, how it is exposed to other parts of Drupal. 'Page' and 'block' are the most commonly used display plugins. Each View also has a 'master' (or 'default') display that includes information shared between all its displays. (See \Drupal\views\Plugin\views\display\DefaultDisplay.) Display plugins extend \Drupal\views\Plugin\views\display\DisplayPluginBase.
  • Display extender: Display extender plugins allow additional options or configurations to added to views across all display types. For example, if you wanted to allow site users to add certain metadata to the rendered output of every view display regardless of display type, you could provide this option as a display extender. Display extender plugins extend \Drupal\views\Plugin\views\display_extender\DisplayExtenderPluginBase.
  • Exposed form: Exposed form plugins are responsible for building, rendering, and controlling exposed forms. Exposed form plugins extend \Drupal\views\Plugin\views\display\DisplayPluginBase.
  • Handlers: Handler plugins help build the view query object that the query plugin then executes to retrieve the data from the storage backend (see below). There are several types of handlers:

    • Area handlers: Extend \Drupal\views\Plugin\views\area\AreaHandlerBase
    • Argument handlers: Extend \Drupal\views\Plugin\views\argument\ArgumentHandlerBase
    • Field handlers: Extend \Drupal\views\Plugin\views\field\FieldHandlerBase
    • Filter handlers: Extend \Drupal\views\Plugin\views\filter\FilterHandlerBase
    • Relationship handlers: Extend \Drupal\views\Plugin\views\relationship\RelationshipHandlerBase
    • Sort handlers: Extend \Drupal\views\Plugin\views\sort:SortHandlerBase
  • Pager: Pager plugins take care of everything regarding pagers, including getting setting the total number of items to render the pager and setting the global pager arrays. Pager plugins extend \Drupal\views\Plugin\views\pager\PagerPluginBase.
  • Query: Query plugins generate and execute a built query object against a particular storage backend, converting the Views query object into an actual query. The only default implementation is SQL. (Note that most handler plugins currently rely on the SQL query plugin.) Query plugins extend \Drupal\views\Plugin\views\query\QueryPluginBase.
  • Row style: Row styles handle rendering each individual record from the main view table. The two default implementations render the entire entity (nodes only), or selected fields. Row style plugins extend \Drupal\views\Plugin\views\row\RowPluginBase).
  • Style: Style plugins control how a view is displayed. For the most part they are object wrappers around theme templates. Examples of styles include HTML lists, tables, etc. Style plugins extend \Drupal\views\Plugin\views\style\StylePluginBase.

@todo Add an explanation for each type of handler. @todo Document how to use annotations and what goes in them. @todo Add @todo Add a separate @todo Document specific options on the appropriate plugin base classes. @todo Add examples.

See also

\Drupal\views\Plugin\views\PluginBase

\Drupal\views\Plugin\views\HandlerBase

File

drupal/core/modules/views/views.api.php, line 8
Describes hooks and plugins provided by the Views module.