Download - Views Handlers & Plugins
-
7/30/2019 Views Handlers & Plugins
1/19
ViewsHandlers & Plug-ins
Sorin Dediu
Drupal developer
-
7/30/2019 Views Handlers & Plugins
2/19
Views handlers
-
7/30/2019 Views Handlers & Plugins
3/19
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.
-
7/30/2019 Views Handlers & Plugins
4/19
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.
-
7/30/2019 Views Handlers & Plugins
5/19
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]
-
7/30/2019 Views Handlers & Plugins
6/19
Handler flows
Handlers have two distinct code flows:- the UI flow
- the view building flow
-
7/30/2019 Views Handlers & Plugins
7/19
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.
-
7/30/2019 Views Handlers & Plugins
8/19
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.
-
7/30/2019 Views Handlers & Plugins
9/19
hook_views_data()
-
7/30/2019 Views Handlers & Plugins
10/19
Extend existing handler
-
7/30/2019 Views Handlers & Plugins
11/19
Views plugins
-
7/30/2019 Views Handlers & Plugins
12/19
What is view plugin
In Views, a plugin is a bit like a handler, but plugins are notdirectly responsible for building the query. Instead, they are
objects that are used to display the view or make other
modifications.
-
7/30/2019 Views Handlers & Plugins
13/19
What is view plugin
There are 12 types of plugins in Views:
-
7/30/2019 Views Handlers & Plugins
14/19
Views plugins types
Display
Style
Row Style Argument Default
Argument Validator
Access
-
7/30/2019 Views Handlers & Plugins
15/19
Views plugins types
Query
Cache
Pager plugins Exposed form plugins
Localization plugins
Display extenders
-
7/30/2019 Views Handlers & Plugins
16/19
hook_views_plugins()
Here is an example of a row style plugin from Views core:
-
7/30/2019 Views Handlers & Plugins
17/19
Pager plugin
Plugin type: pager
-
7/30/2019 Views Handlers & Plugins
18/19
-
7/30/2019 Views Handlers & Plugins
19/19
THANK YOU
QUESTIONS ?