You are on page 1of 19

Views Handlers & Plug-ins

Sorin Dediu Drupal developer

Views handlers

What is views handler


Handler is an object that is part of the view and is part of the query building flow. Most handlers are just extensions of existing classes with a few tweaks that are specific to the field in question.

Handler registration
Handlers are stored in their own files and loaded on demand. Like all other module files, they must first be registered through the module's info file.

Handler registration
Put this in your module.info files[] = includes/views/handlers/example_handler_argument_string.inc

Handler declaration format: [module]_handler_[type]_[tablename]_[fieldname]

Handler flows

Handlers have two distinct code flows: - the UI flow - the view building flow

The view building flow


For the query flow: - handler->construct()
- Create the initial handler; at this time it is not yet attached to a view. It is here that you can set basic defaults if needed, but there will be no knowledge of the environment yet.

- handler->set_definition()
- Set the data from hook_views_data() relevant to the handler.

- handler->init()
- Attach the handler to a view, and usually provides the options from the display.

- handler->pre_query()
- Run prior to the query() stage to do early processing.

The view building flow


- handler->query()
- Do the bulk of the work this handler needs to do to add itself to the query.

Fields with output: - handler->pre_render(&$values)


- Called prior to the actual rendering, this allows handlers to query for extra data; the entire result set is available here, and this is where items that have "multiple values" per record can do their extra query for all of the records available.

- handler->render()
- This does the actual work of rendering the field.

hook_views_data()

Extend existing handler

Views plugins

What is view plugin

In Views, a plugin is a bit like a handler, but plugins are not directly responsible for building the query. Instead, they are objects that are used to display the view or make other modifications.

What is view plugin

There are 12 types of plugins in Views:

Views plugins types


Display Style Row Style Argument Default Argument Validator Access

Views plugins types


Query Cache Pager plugins Exposed form plugins Localization plugins Display extenders

hook_views_plugins()
Here is an example of a row style plugin from Views core:

Pager plugin
Plugin type: pager

THANK YOU

QUESTIONS ?

You might also like