Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /**
|
Chris@0
|
4 * @file
|
Chris@0
|
5 * Describes hooks and plugins provided by the Views module.
|
Chris@0
|
6 */
|
Chris@0
|
7
|
Chris@0
|
8 use Drupal\Core\Language\LanguageInterface;
|
Chris@0
|
9 use Drupal\views\Plugin\views\cache\CachePluginBase;
|
Chris@0
|
10 use Drupal\views\Plugin\views\PluginBase;
|
Chris@0
|
11 use Drupal\views\ViewExecutable;
|
Chris@0
|
12
|
Chris@0
|
13 /**
|
Chris@0
|
14 * @defgroup views_overview Views overview
|
Chris@0
|
15 * @{
|
Chris@0
|
16 * Overview of the Views module API
|
Chris@0
|
17 *
|
Chris@0
|
18 * The Views module is a generalized query and display engine, which can be used
|
Chris@0
|
19 * to make views (formatted lists, grids, feeds, and other output) of items
|
Chris@0
|
20 * (often entities, but can be other types of data). Developers can interact
|
Chris@0
|
21 * with Views in several ways:
|
Chris@0
|
22 * - Provide plugins: Views plugins govern nearly every aspect of views,
|
Chris@0
|
23 * including querying (sorting, filtering, etc.) and display (at several
|
Chris@0
|
24 * levels of granularity, ranging from the entire view to the details of a
|
Chris@0
|
25 * field). See the @link views_plugins Views plugins topic @endlink for
|
Chris@0
|
26 * more information.
|
Chris@0
|
27 * - Provide data: Data types can be provided to Views by implementing
|
Chris@0
|
28 * hook_views_data(), and data types provided by other modules can be altered
|
Chris@0
|
29 * by implementing hook_views_data_alter(). To provide views data for an
|
Chris@0
|
30 * entity, create a class implementing
|
Chris@0
|
31 * \Drupal\views\EntityViewsDataInterface and reference this in the
|
Chris@0
|
32 * "views_data" annotation in the entity class. You can autogenerate big parts
|
Chris@0
|
33 * of the integration if you extend the \Drupal\views\EntityViewsData base
|
Chris@0
|
34 * class. See the @link entity_api Entity API topic @endlink for more
|
Chris@0
|
35 * information about entities.
|
Chris@0
|
36 * - Implement hooks: A few operations in Views can be influenced by hooks.
|
Chris@0
|
37 * See the @link views_hooks Views hooks topic @endlink for a list.
|
Chris@0
|
38 * - Theming: See the @link views_templates Views templates topic @endlink
|
Chris@0
|
39 * for more information.
|
Chris@0
|
40 *
|
Chris@0
|
41 * @see \Drupal\views\ViewExecutable
|
Chris@0
|
42 * @see \Drupal\views\Views
|
Chris@0
|
43 * @}
|
Chris@0
|
44 */
|
Chris@0
|
45
|
Chris@0
|
46 /**
|
Chris@0
|
47 * @defgroup views_plugins Views plugins
|
Chris@0
|
48 * @{
|
Chris@0
|
49 * Overview of views plugins
|
Chris@0
|
50 *
|
Chris@0
|
51 * Views plugins are objects that are used to build and render the view.
|
Chris@0
|
52 * See individual views plugin topics for more information about the
|
Chris@0
|
53 * specifics of each plugin type, and the
|
Chris@0
|
54 * @link plugin_api Plugin API topic @endlink for more information about
|
Chris@0
|
55 * plugins in general.
|
Chris@0
|
56 *
|
Chris@0
|
57 * Some Views plugins are known as handlers. Handler plugins help build the
|
Chris@0
|
58 * view query object: filtering, contextual filtering, sorting, relationships,
|
Chris@0
|
59 * etc.
|
Chris@0
|
60 *
|
Chris@0
|
61 * @todo Document specific options on the appropriate plugin base classes.
|
Chris@0
|
62 * @todo Add examples.
|
Chris@0
|
63 *
|
Chris@0
|
64 * @ingroup views_overview
|
Chris@0
|
65 * @see \Drupal\views\Plugin\views\PluginBase
|
Chris@0
|
66 * @see \Drupal\views\Plugin\views\HandlerBase
|
Chris@0
|
67 * @see plugin_api
|
Chris@0
|
68 * @see annotation
|
Chris@0
|
69 * @}
|
Chris@0
|
70 */
|
Chris@0
|
71
|
Chris@0
|
72 /**
|
Chris@0
|
73 * @defgroup views_hooks Views hooks
|
Chris@0
|
74 * @{
|
Chris@0
|
75 * Hooks that allow other modules to implement the Views API.
|
Chris@0
|
76 * @ingroup views_overview
|
Chris@0
|
77 * @}
|
Chris@0
|
78 */
|
Chris@0
|
79
|
Chris@0
|
80 /**
|
Chris@0
|
81 * @addtogroup hooks
|
Chris@0
|
82 * @{
|
Chris@0
|
83 */
|
Chris@0
|
84
|
Chris@0
|
85 /**
|
Chris@0
|
86 * Analyze a view to provide warnings about its configuration.
|
Chris@0
|
87 *
|
Chris@0
|
88 * @param \Drupal\views\ViewExecutable $view
|
Chris@0
|
89 * The view being executed.
|
Chris@0
|
90 *
|
Chris@0
|
91 * @return array
|
Chris@0
|
92 * Array of warning messages built by Analyzer::formatMessage to be displayed
|
Chris@0
|
93 * to the user following analysis of the view.
|
Chris@0
|
94 */
|
Chris@0
|
95 function hook_views_analyze(Drupal\views\ViewExecutable $view) {
|
Chris@0
|
96 $messages = [];
|
Chris@0
|
97
|
Chris@0
|
98 if ($view->display_handler->options['pager']['type'] == 'none') {
|
Chris@0
|
99 $messages[] = Drupal\views\Analyzer::formatMessage(t('This view has no pager. This could cause performance issues when the view contains many items.'), 'warning');
|
Chris@0
|
100 }
|
Chris@0
|
101
|
Chris@0
|
102 return $messages;
|
Chris@0
|
103 }
|
Chris@0
|
104
|
Chris@0
|
105 /**
|
Chris@0
|
106 * Describe data tables and fields (or the equivalent) to Views.
|
Chris@0
|
107 *
|
Chris@0
|
108 * The table and fields are processed in Views using various plugins. See
|
Chris@0
|
109 * the @link views_plugins Views plugins topic @endlink for more information.
|
Chris@0
|
110 *
|
Chris@0
|
111 * To provide views data for an entity, instead of implementing this hook,
|
Chris@0
|
112 * create a class implementing \Drupal\views\EntityViewsDataInterface and
|
Chris@0
|
113 * reference this in the "views" annotation in the entity class. The return
|
Chris@0
|
114 * value of the getViewsData() method on the interface is the same as this hook,
|
Chris@0
|
115 * and base class in \Drupal\views\EntityViewsData will take care of adding the
|
Chris@0
|
116 * basic Views tables and fields for your entity. See the
|
Chris@0
|
117 * @link entity_api Entity API topic @endlink for more information about
|
Chris@0
|
118 * entities.
|
Chris@0
|
119 *
|
Chris@0
|
120 * The data described with this hook is fetched and retrieved by
|
Chris@0
|
121 * \Drupal\views\Views::viewsData()->get().
|
Chris@0
|
122 *
|
Chris@0
|
123 * @return array
|
Chris@0
|
124 * An associative array describing the structure of database tables and fields
|
Chris@0
|
125 * (and their equivalents) provided for use in Views. At the outermost level,
|
Chris@0
|
126 * the keys are the names used internally by Views for the tables (usually the
|
Chris@0
|
127 * actual table name). Each table's array describes the table itself, how to
|
Chris@0
|
128 * join to other tables, and the fields that are part of the table. The sample
|
Chris@0
|
129 * function body provides documentation of the details.
|
Chris@0
|
130 *
|
Chris@0
|
131 * @see hook_views_data_alter()
|
Chris@0
|
132 */
|
Chris@0
|
133 function hook_views_data() {
|
Chris@0
|
134 // This example describes how to write hook_views_data() for a table defined
|
Chris@0
|
135 // like this:
|
Chris@0
|
136 // CREATE TABLE example_table (
|
Chris@0
|
137 // nid INT(11) NOT NULL COMMENT 'Primary key: {node}.nid.',
|
Chris@0
|
138 // plain_text_field VARCHAR(32) COMMENT 'Just a plain text field.',
|
Chris@0
|
139 // numeric_field INT(11) COMMENT 'Just a numeric field.',
|
Chris@0
|
140 // boolean_field INT(1) COMMENT 'Just an on/off field.',
|
Chris@0
|
141 // timestamp_field INT(8) COMMENT 'Just a timestamp field.',
|
Chris@0
|
142 // langcode VARCHAR(12) COMMENT 'Language code field.',
|
Chris@0
|
143 // PRIMARY KEY(nid)
|
Chris@0
|
144 // );
|
Chris@0
|
145
|
Chris@0
|
146 // Define the return array.
|
Chris@0
|
147 $data = [];
|
Chris@0
|
148
|
Chris@0
|
149 // The outermost keys of $data are Views table names, which should usually
|
Chris@0
|
150 // be the same as the hook_schema() table names.
|
Chris@0
|
151 $data['example_table'] = [];
|
Chris@0
|
152
|
Chris@0
|
153 // The value corresponding to key 'table' gives properties of the table
|
Chris@0
|
154 // itself.
|
Chris@0
|
155 $data['example_table']['table'] = [];
|
Chris@0
|
156
|
Chris@0
|
157 // Within 'table', the value of 'group' (translated string) is used as a
|
Chris@0
|
158 // prefix in Views UI for this table's fields, filters, etc. When adding
|
Chris@0
|
159 // a field, filter, etc. you can also filter by the group.
|
Chris@0
|
160 $data['example_table']['table']['group'] = t('Example table');
|
Chris@0
|
161
|
Chris@0
|
162 // Within 'table', the value of 'provider' is the module that provides schema
|
Chris@0
|
163 // or the entity type that causes the table to exist. Setting this ensures
|
Chris@0
|
164 // that views have the correct dependencies. This is automatically set to the
|
Chris@0
|
165 // module that implements hook_views_data().
|
Chris@0
|
166 $data['example_table']['table']['provider'] = 'example_module';
|
Chris@0
|
167
|
Chris@0
|
168 // Some tables are "base" tables, meaning that they can be the base tables
|
Chris@0
|
169 // for views. Non-base tables can only be brought in via relationships in
|
Chris@0
|
170 // views based on other tables. To define a table to be a base table, add
|
Chris@0
|
171 // key 'base' to the 'table' array:
|
Chris@0
|
172 $data['example_table']['table']['base'] = [
|
Chris@0
|
173 // Identifier (primary) field in this table for Views.
|
Chris@0
|
174 'field' => 'nid',
|
Chris@0
|
175 // Label in the UI.
|
Chris@0
|
176 'title' => t('Example table'),
|
Chris@0
|
177 // Longer description in the UI. Required.
|
Chris@0
|
178 'help' => t('Example table contains example content and can be related to nodes.'),
|
Chris@0
|
179 'weight' => -10,
|
Chris@0
|
180 ];
|
Chris@0
|
181
|
Chris@0
|
182 // Some tables have an implicit, automatic relationship to other tables,
|
Chris@0
|
183 // meaning that when the other table is available in a view (either as the
|
Chris@0
|
184 // base table or through a relationship), this table's fields, filters, etc.
|
Chris@0
|
185 // are automatically made available without having to add an additional
|
Chris@0
|
186 // relationship. To define an implicit relationship that will make your
|
Chris@0
|
187 // table automatically available when another table is present, add a 'join'
|
Chris@0
|
188 // section to your 'table' section. Note that it is usually only a good idea
|
Chris@0
|
189 // to do this for one-to-one joins, because otherwise your automatic join
|
Chris@0
|
190 // will add more rows to the view. It is also not a good idea to do this if
|
Chris@0
|
191 // most views won't need your table -- if that is the case, define a
|
Chris@0
|
192 // relationship instead (see below).
|
Chris@0
|
193 //
|
Chris@0
|
194 // If you've decided an automatic join is a good idea, here's how to do it;
|
Chris@0
|
195 // the resulting SQL query will look something like this:
|
Chris@0
|
196 // ... FROM example_table et ... JOIN node_field_data nfd
|
Chris@0
|
197 // ON et.nid = nfd.nid AND ('extra' clauses will be here) ...
|
Chris@0
|
198 // although the table aliases will be different.
|
Chris@0
|
199 $data['example_table']['table']['join'] = [
|
Chris@0
|
200 // Within the 'join' section, list one or more tables to automatically
|
Chris@0
|
201 // join to. In this example, every time 'node_field_data' is available in
|
Chris@0
|
202 // a view, 'example_table' will be too. The array keys here are the array
|
Chris@0
|
203 // keys for the other tables, given in their hook_views_data()
|
Chris@0
|
204 // implementations. If the table listed here is from another module's
|
Chris@0
|
205 // hook_views_data() implementation, make sure your module depends on that
|
Chris@0
|
206 // other module.
|
Chris@0
|
207 'node_field_data' => [
|
Chris@0
|
208 // Primary key field in node_field_data to use in the join.
|
Chris@0
|
209 'left_field' => 'nid',
|
Chris@0
|
210 // Foreign key field in example_table to use in the join.
|
Chris@0
|
211 'field' => 'nid',
|
Chris@0
|
212 // 'extra' is an array of additional conditions on the join.
|
Chris@0
|
213 'extra' => [
|
Chris@0
|
214 0 => [
|
Chris@0
|
215 // Adds AND node_field_data.published = TRUE to the join.
|
Chris@0
|
216 'field' => 'published',
|
Chris@0
|
217 'value' => TRUE,
|
Chris@0
|
218 ],
|
Chris@0
|
219 1 => [
|
Chris@0
|
220 // Adds AND example_table.numeric_field = 1 to the join.
|
Chris@0
|
221 'left_field' => 'numeric_field',
|
Chris@0
|
222 'value' => 1,
|
Chris@0
|
223 // If true, the value will not be surrounded in quotes.
|
Chris@0
|
224 'numeric' => TRUE,
|
Chris@0
|
225 ],
|
Chris@0
|
226 2 => [
|
Chris@0
|
227 // Adds AND example_table.boolean_field <>
|
Chris@0
|
228 // node_field_data.published to the join.
|
Chris@0
|
229 'field' => 'published',
|
Chris@0
|
230 'left_field' => 'boolean_field',
|
Chris@0
|
231 // The operator used, Defaults to "=".
|
Chris@0
|
232 'operator' => '!=',
|
Chris@0
|
233 ],
|
Chris@0
|
234 ],
|
Chris@0
|
235 ],
|
Chris@0
|
236 ];
|
Chris@0
|
237
|
Chris@0
|
238 // You can also do a more complex join, where in order to get to a certain
|
Chris@0
|
239 // base table defined in a hook_views_data() implementation, you will join
|
Chris@0
|
240 // to a different table that Views knows how to auto-join to the base table.
|
Chris@0
|
241 // For instance, if another module that your module depends on had
|
Chris@0
|
242 // defined a table 'foo' with an automatic join to 'node_field_table' (as
|
Chris@0
|
243 // shown above), you could join to 'node_field_table' via the 'foo' table.
|
Chris@0
|
244 // Here's how to do this, and the resulting SQL query would look something
|
Chris@0
|
245 // like this:
|
Chris@0
|
246 // ... FROM example_table et ... JOIN foo foo
|
Chris@0
|
247 // ON et.nid = foo.nid AND ('extra' clauses will be here) ...
|
Chris@0
|
248 // JOIN node_field_data nfd ON (definition of the join from the foo
|
Chris@0
|
249 // module goes here) ...
|
Chris@0
|
250 // although the table aliases will be different.
|
Chris@0
|
251 $data['example_table']['table']['join']['node_field_data'] = [
|
Chris@0
|
252 // 'node_field_data' above is the base we're joining to in Views.
|
Chris@0
|
253 // 'left_table' is the table we're actually joining to, in order to get to
|
Chris@0
|
254 // 'node_field_data'. It has to be something that Views knows how to join
|
Chris@0
|
255 // to 'node_field_data'.
|
Chris@0
|
256 'left_table' => 'foo',
|
Chris@0
|
257 'left_field' => 'nid',
|
Chris@0
|
258 'field' => 'nid',
|
Chris@0
|
259 // 'extra' is an array of additional conditions on the join.
|
Chris@0
|
260 'extra' => [
|
Chris@0
|
261 // This syntax matches additional fields in the two tables:
|
Chris@0
|
262 // ... AND foo.langcode = example_table.langcode ...
|
Chris@0
|
263 ['left_field' => 'langcode', 'field' => 'langcode'],
|
Chris@0
|
264 // This syntax adds a condition on our table. 'operator' defaults to
|
Chris@0
|
265 // '=' for non-array values, or 'IN' for array values.
|
Chris@0
|
266 // ... AND example_table.numeric_field > 0 ...
|
Chris@0
|
267 ['field' => 'numeric_field', 'value' => 0, 'numeric' => TRUE, 'operator' => '>'],
|
Chris@0
|
268 ],
|
Chris@0
|
269 ];
|
Chris@0
|
270
|
Chris@0
|
271 // Other array elements at the top level of your table's array describe
|
Chris@0
|
272 // individual database table fields made available to Views. The array keys
|
Chris@0
|
273 // are the names (unique within the table) used by Views for the fields,
|
Chris@0
|
274 // usually equal to the database field names.
|
Chris@0
|
275 //
|
Chris@0
|
276 // Each field entry must have the following elements:
|
Chris@0
|
277 // - title: Translated label for the field in the UI.
|
Chris@0
|
278 // - help: Description of the field in the UI.
|
Chris@0
|
279 //
|
Chris@0
|
280 // Each field entry may also have one or more of the following elements,
|
Chris@0
|
281 // describing "handlers" (plugins) for the field:
|
Chris@0
|
282 // - relationship: Specifies a handler that allows this field to be used
|
Chris@0
|
283 // to define a relationship to another table in Views.
|
Chris@0
|
284 // - field: Specifies a handler to make it available to Views as a field.
|
Chris@0
|
285 // - filter: Specifies a handler to make it available to Views as a filter.
|
Chris@0
|
286 // - sort: Specifies a handler to make it available to Views as a sort.
|
Chris@0
|
287 // - argument: Specifies a handler to make it available to Views as an
|
Chris@0
|
288 // argument, or contextual filter as it is known in the UI.
|
Chris@0
|
289 // - area: Specifies a handler to make it available to Views to add content
|
Chris@0
|
290 // to the header, footer, or as no result behavior.
|
Chris@0
|
291 //
|
Chris@0
|
292 // Note that when specifying handlers, you must give the handler plugin ID
|
Chris@0
|
293 // and you may also specify overrides for various settings that make up the
|
Chris@0
|
294 // plugin definition. See examples below; the Boolean example demonstrates
|
Chris@0
|
295 // setting overrides.
|
Chris@0
|
296
|
Chris@0
|
297 // Node ID field, exposed as relationship only, since it is a foreign key
|
Chris@0
|
298 // in this table.
|
Chris@0
|
299 $data['example_table']['nid'] = [
|
Chris@0
|
300 'title' => t('Example content'),
|
Chris@0
|
301 'help' => t('Relate example content to the node content'),
|
Chris@0
|
302
|
Chris@0
|
303 // Define a relationship to the node_field_data table, so views whose
|
Chris@0
|
304 // base table is example_table can add a relationship to nodes. To make a
|
Chris@0
|
305 // relationship in the other direction, you can:
|
Chris@0
|
306 // - Use hook_views_data_alter() -- see the function body example on that
|
Chris@0
|
307 // hook for details.
|
Chris@0
|
308 // - Use the implicit join method described above.
|
Chris@0
|
309 'relationship' => [
|
Chris@0
|
310 // Views name of the table to join to for the relationship.
|
Chris@0
|
311 'base' => 'node_field_data',
|
Chris@0
|
312 // Database field name in the other table to join on.
|
Chris@0
|
313 'base field' => 'nid',
|
Chris@0
|
314 // ID of relationship handler plugin to use.
|
Chris@0
|
315 'id' => 'standard',
|
Chris@0
|
316 // Default label for relationship in the UI.
|
Chris@0
|
317 'label' => t('Example node'),
|
Chris@0
|
318 ],
|
Chris@0
|
319 ];
|
Chris@0
|
320
|
Chris@0
|
321 // Plain text field, exposed as a field, sort, filter, and argument.
|
Chris@0
|
322 $data['example_table']['plain_text_field'] = [
|
Chris@0
|
323 'title' => t('Plain text field'),
|
Chris@0
|
324 'help' => t('Just a plain text field.'),
|
Chris@0
|
325
|
Chris@0
|
326 'field' => [
|
Chris@0
|
327 // ID of field handler plugin to use.
|
Chris@0
|
328 'id' => 'standard',
|
Chris@0
|
329 ],
|
Chris@0
|
330
|
Chris@0
|
331 'sort' => [
|
Chris@0
|
332 // ID of sort handler plugin to use.
|
Chris@0
|
333 'id' => 'standard',
|
Chris@0
|
334 ],
|
Chris@0
|
335
|
Chris@0
|
336 'filter' => [
|
Chris@0
|
337 // ID of filter handler plugin to use.
|
Chris@0
|
338 'id' => 'string',
|
Chris@0
|
339 ],
|
Chris@0
|
340
|
Chris@0
|
341 'argument' => [
|
Chris@0
|
342 // ID of argument handler plugin to use.
|
Chris@0
|
343 'id' => 'string',
|
Chris@0
|
344 ],
|
Chris@0
|
345 ];
|
Chris@0
|
346
|
Chris@0
|
347 // Numeric field, exposed as a field, sort, filter, and argument.
|
Chris@0
|
348 $data['example_table']['numeric_field'] = [
|
Chris@0
|
349 'title' => t('Numeric field'),
|
Chris@0
|
350 'help' => t('Just a numeric field.'),
|
Chris@0
|
351
|
Chris@0
|
352 'field' => [
|
Chris@0
|
353 // ID of field handler plugin to use.
|
Chris@0
|
354 'id' => 'numeric',
|
Chris@0
|
355 ],
|
Chris@0
|
356
|
Chris@0
|
357 'sort' => [
|
Chris@0
|
358 // ID of sort handler plugin to use.
|
Chris@0
|
359 'id' => 'standard',
|
Chris@0
|
360 ],
|
Chris@0
|
361
|
Chris@0
|
362 'filter' => [
|
Chris@0
|
363 // ID of filter handler plugin to use.
|
Chris@0
|
364 'id' => 'numeric',
|
Chris@0
|
365 ],
|
Chris@0
|
366
|
Chris@0
|
367 'argument' => [
|
Chris@0
|
368 // ID of argument handler plugin to use.
|
Chris@0
|
369 'id' => 'numeric',
|
Chris@0
|
370 ],
|
Chris@0
|
371 ];
|
Chris@0
|
372
|
Chris@0
|
373 // Boolean field, exposed as a field, sort, and filter. The filter section
|
Chris@0
|
374 // illustrates overriding various settings.
|
Chris@0
|
375 $data['example_table']['boolean_field'] = [
|
Chris@0
|
376 'title' => t('Boolean field'),
|
Chris@0
|
377 'help' => t('Just an on/off field.'),
|
Chris@0
|
378
|
Chris@0
|
379 'field' => [
|
Chris@0
|
380 // ID of field handler plugin to use.
|
Chris@0
|
381 'id' => 'boolean',
|
Chris@0
|
382 ],
|
Chris@0
|
383
|
Chris@0
|
384 'sort' => [
|
Chris@0
|
385 // ID of sort handler plugin to use.
|
Chris@0
|
386 'id' => 'standard',
|
Chris@0
|
387 ],
|
Chris@0
|
388
|
Chris@0
|
389 'filter' => [
|
Chris@0
|
390 // ID of filter handler plugin to use.
|
Chris@0
|
391 'id' => 'boolean',
|
Chris@0
|
392 // Override the generic field title, so that the filter uses a different
|
Chris@0
|
393 // label in the UI.
|
Chris@0
|
394 'label' => t('Published'),
|
Chris@0
|
395 // Override the default BooleanOperator filter handler's 'type' setting,
|
Chris@0
|
396 // to display this as a "Yes/No" filter instead of a "True/False" filter.
|
Chris@0
|
397 'type' => 'yes-no',
|
Chris@0
|
398 // Override the default Boolean filter handler's 'use_equal' setting, to
|
Chris@0
|
399 // make the query use 'boolean_field = 1' instead of 'boolean_field <> 0'.
|
Chris@0
|
400 'use_equal' => TRUE,
|
Chris@0
|
401 ],
|
Chris@0
|
402 ];
|
Chris@0
|
403
|
Chris@0
|
404 // Integer timestamp field, exposed as a field, sort, and filter.
|
Chris@0
|
405 $data['example_table']['timestamp_field'] = [
|
Chris@0
|
406 'title' => t('Timestamp field'),
|
Chris@0
|
407 'help' => t('Just a timestamp field.'),
|
Chris@0
|
408
|
Chris@0
|
409 'field' => [
|
Chris@0
|
410 // ID of field handler plugin to use.
|
Chris@0
|
411 'id' => 'date',
|
Chris@0
|
412 ],
|
Chris@0
|
413
|
Chris@0
|
414 'sort' => [
|
Chris@0
|
415 // ID of sort handler plugin to use.
|
Chris@0
|
416 'id' => 'date',
|
Chris@0
|
417 ],
|
Chris@0
|
418
|
Chris@0
|
419 'filter' => [
|
Chris@0
|
420 // ID of filter handler plugin to use.
|
Chris@0
|
421 'id' => 'date',
|
Chris@0
|
422 ],
|
Chris@0
|
423 ];
|
Chris@0
|
424
|
Chris@0
|
425 // Area example. Areas are not generally associated with actual data
|
Chris@0
|
426 // tables and fields. This example is from views_views_data(), which defines
|
Chris@0
|
427 // the "Global" table (not really a table, but a group of Fields, Filters,
|
Chris@0
|
428 // etc. that are grouped into section "Global" in the UI). Here's the
|
Chris@0
|
429 // definition of the generic "Text area":
|
Chris@0
|
430 $data['views']['area'] = [
|
Chris@0
|
431 'title' => t('Text area'),
|
Chris@0
|
432 'help' => t('Provide markup text for the area.'),
|
Chris@0
|
433 'area' => [
|
Chris@0
|
434 // ID of the area handler plugin to use.
|
Chris@0
|
435 'id' => 'text',
|
Chris@0
|
436 ],
|
Chris@0
|
437 ];
|
Chris@0
|
438
|
Chris@0
|
439 return $data;
|
Chris@0
|
440 }
|
Chris@0
|
441
|
Chris@0
|
442 /**
|
Chris@0
|
443 * Alter the table and field information from hook_views_data().
|
Chris@0
|
444 *
|
Chris@0
|
445 * @param array $data
|
Chris@0
|
446 * An array of all information about Views tables and fields, collected from
|
Chris@0
|
447 * hook_views_data(), passed by reference.
|
Chris@0
|
448 *
|
Chris@0
|
449 * @see hook_views_data()
|
Chris@0
|
450 */
|
Chris@0
|
451 function hook_views_data_alter(array &$data) {
|
Chris@0
|
452 // Alter the title of the node_field_data:nid field in the Views UI.
|
Chris@0
|
453 $data['node_field_data']['nid']['title'] = t('Node-Nid');
|
Chris@0
|
454
|
Chris@0
|
455 // Add an additional field to the users_field_data table.
|
Chris@0
|
456 $data['users_field_data']['example_field'] = [
|
Chris@0
|
457 'title' => t('Example field'),
|
Chris@0
|
458 'help' => t('Some example content that references a user'),
|
Chris@0
|
459
|
Chris@0
|
460 'field' => [
|
Chris@0
|
461 // ID of the field handler to use.
|
Chris@0
|
462 'id' => 'example_field',
|
Chris@0
|
463 ],
|
Chris@0
|
464 ];
|
Chris@0
|
465
|
Chris@0
|
466 // Change the handler of the node title field, presumably to a handler plugin
|
Chris@0
|
467 // you define in your module. Give the ID of this plugin.
|
Chris@0
|
468 $data['node_field_data']['title']['field']['id'] = 'node_title';
|
Chris@0
|
469
|
Chris@0
|
470 // Add a relationship that will allow a view whose base table is 'foo' (from
|
Chris@0
|
471 // another module) to have a relationship to 'example_table' (from my module),
|
Chris@0
|
472 // via joining foo.fid to example_table.eid.
|
Chris@0
|
473 //
|
Chris@0
|
474 // This relationship has to be added to the 'foo' Views data, which my module
|
Chris@0
|
475 // does not control, so it must be done in hook_views_data_alter(), not
|
Chris@0
|
476 // hook_views_data().
|
Chris@0
|
477 //
|
Chris@0
|
478 // In Views data definitions, each field can have only one relationship. So
|
Chris@0
|
479 // rather than adding this relationship directly to the $data['foo']['fid']
|
Chris@0
|
480 // field entry, which could overwrite an existing relationship, we define
|
Chris@0
|
481 // a dummy field key to handle the relationship.
|
Chris@0
|
482 $data['foo']['unique_dummy_name'] = [
|
Chris@0
|
483 'title' => t('Title seen while adding relationship'),
|
Chris@0
|
484 'help' => t('More information about the relationship'),
|
Chris@0
|
485
|
Chris@0
|
486 'relationship' => [
|
Chris@0
|
487 // Views name of the table being joined to from foo.
|
Chris@0
|
488 'base' => 'example_table',
|
Chris@0
|
489 // Database field name in example_table for the join.
|
Chris@0
|
490 'base field' => 'eid',
|
Chris@0
|
491 // Real database field name in foo for the join, to override
|
Chris@0
|
492 // 'unique_dummy_name'.
|
Chris@0
|
493 'field' => 'fid',
|
Chris@0
|
494 // ID of relationship handler plugin to use.
|
Chris@0
|
495 'id' => 'standard',
|
Chris@0
|
496 'label' => t('Default label for relationship'),
|
Chris@0
|
497 ],
|
Chris@0
|
498 ];
|
Chris@0
|
499
|
Chris@0
|
500 // Note that the $data array is not returned – it is modified by reference.
|
Chris@0
|
501 }
|
Chris@0
|
502
|
Chris@0
|
503 /**
|
Chris@0
|
504 * Override the default Views data for a Field API field.
|
Chris@0
|
505 *
|
Chris@0
|
506 * The field module's implementation of hook_views_data() invokes this for each
|
Chris@0
|
507 * field storage, in the module that defines the field type. It is not invoked
|
Chris@0
|
508 * in other modules.
|
Chris@0
|
509 *
|
Chris@0
|
510 * If no hook implementation exists, hook_views_data() falls back to
|
Chris@0
|
511 * views_field_default_views_data().
|
Chris@0
|
512 *
|
Chris@0
|
513 * @param \Drupal\field\FieldStorageConfigInterface $field_storage
|
Chris@0
|
514 * The field storage config entity.
|
Chris@0
|
515 *
|
Chris@0
|
516 * @return array
|
Chris@0
|
517 * An array of views data, in the same format as the return value of
|
Chris@0
|
518 * hook_views_data().
|
Chris@0
|
519 *
|
Chris@0
|
520 * @see views_views_data()
|
Chris@0
|
521 * @see hook_field_views_data_alter()
|
Chris@0
|
522 * @see hook_field_views_data_views_data_alter()
|
Chris@0
|
523 */
|
Chris@0
|
524 function hook_field_views_data(\Drupal\field\FieldStorageConfigInterface $field_storage) {
|
Chris@0
|
525 $data = views_field_default_views_data($field_storage);
|
Chris@0
|
526 foreach ($data as $table_name => $table_data) {
|
Chris@0
|
527 // Add the relationship only on the target_id field.
|
Chris@0
|
528 $data[$table_name][$field_storage->getName() . '_target_id']['relationship'] = [
|
Chris@0
|
529 'id' => 'standard',
|
Chris@0
|
530 'base' => 'file_managed',
|
Chris@0
|
531 'base field' => 'target_id',
|
Chris@0
|
532 'label' => t('image from @field_name', ['@field_name' => $field_storage->getName()]),
|
Chris@0
|
533 ];
|
Chris@0
|
534 }
|
Chris@0
|
535
|
Chris@0
|
536 return $data;
|
Chris@0
|
537 }
|
Chris@0
|
538
|
Chris@0
|
539 /**
|
Chris@0
|
540 * Alter the Views data for a single Field API field.
|
Chris@0
|
541 *
|
Chris@0
|
542 * This is called on all modules even if there is no hook_field_views_data()
|
Chris@0
|
543 * implementation for the field, and therefore may be used to alter the
|
Chris@0
|
544 * default data that views_field_default_views_data() supplies for the
|
Chris@0
|
545 * field storage.
|
Chris@0
|
546 *
|
Chris@0
|
547 * @param array $data
|
Chris@0
|
548 * The views data for the field storage. This has the same format as the
|
Chris@0
|
549 * return value of hook_views_data().
|
Chris@0
|
550 * @param \Drupal\field\FieldStorageConfigInterface $field_storage
|
Chris@0
|
551 * The field storage config entity.
|
Chris@0
|
552 *
|
Chris@0
|
553 * @see views_views_data()
|
Chris@0
|
554 * @see hook_field_views_data()
|
Chris@0
|
555 * @see hook_field_views_data_views_data_alter()
|
Chris@0
|
556 */
|
Chris@0
|
557 function hook_field_views_data_alter(array &$data, \Drupal\field\FieldStorageConfigInterface $field_storage) {
|
Chris@0
|
558 $entity_type_id = $field_storage->getTargetEntityTypeId();
|
Chris@0
|
559 $field_name = $field_storage->getName();
|
Chris@0
|
560 $entity_type = \Drupal::entityManager()->getDefinition($entity_type_id);
|
Chris@0
|
561 $pseudo_field_name = 'reverse_' . $field_name . '_' . $entity_type_id;
|
Chris@0
|
562 $table_mapping = \Drupal::entityManager()->getStorage($entity_type_id)->getTableMapping();
|
Chris@0
|
563
|
Chris@0
|
564 list($label) = views_entity_field_label($entity_type_id, $field_name);
|
Chris@0
|
565
|
Chris@0
|
566 $data['file_managed'][$pseudo_field_name]['relationship'] = [
|
Chris@0
|
567 'title' => t('@entity using @field', ['@entity' => $entity_type->getLabel(), '@field' => $label]),
|
Chris@0
|
568 'help' => t('Relate each @entity with a @field set to the image.', ['@entity' => $entity_type->getLabel(), '@field' => $label]),
|
Chris@0
|
569 'id' => 'entity_reverse',
|
Chris@0
|
570 'field_name' => $field_name,
|
Chris@0
|
571 'entity_type' => $entity_type_id,
|
Chris@0
|
572 'field table' => $table_mapping->getDedicatedDataTableName($field_storage),
|
Chris@0
|
573 'field field' => $field_name . '_target_id',
|
Chris@0
|
574 'base' => $entity_type->getBaseTable(),
|
Chris@0
|
575 'base field' => $entity_type->getKey('id'),
|
Chris@0
|
576 'label' => $field_name,
|
Chris@0
|
577 'join_extra' => [
|
Chris@0
|
578 0 => [
|
Chris@0
|
579 'field' => 'deleted',
|
Chris@0
|
580 'value' => 0,
|
Chris@0
|
581 'numeric' => TRUE,
|
Chris@0
|
582 ],
|
Chris@0
|
583 ],
|
Chris@0
|
584 ];
|
Chris@0
|
585 }
|
Chris@0
|
586
|
Chris@0
|
587 /**
|
Chris@0
|
588 * Alter the Views data on a per field basis.
|
Chris@0
|
589 *
|
Chris@0
|
590 * The field module's implementation of hook_views_data_alter() invokes this for
|
Chris@0
|
591 * each field storage, in the module that defines the field type. It is not
|
Chris@0
|
592 * invoked in other modules.
|
Chris@0
|
593 *
|
Chris@0
|
594 * Unlike hook_field_views_data_alter(), this operates on the whole of the views
|
Chris@0
|
595 * data. This allows a field type to add data that concerns its fields in
|
Chris@0
|
596 * other tables, which would not yet be defined at the point when
|
Chris@0
|
597 * hook_field_views_data() and hook_field_views_data_alter() are invoked. For
|
Chris@0
|
598 * example, entityreference adds reverse relationships on the tables for the
|
Chris@0
|
599 * entities which are referenced by entityreference fields.
|
Chris@0
|
600 *
|
Chris@0
|
601 * (Note: this is weirdly named so as not to conflict with
|
Chris@0
|
602 * hook_field_views_data_alter().)
|
Chris@0
|
603 *
|
Chris@0
|
604 * @param array $data
|
Chris@0
|
605 * The views data.
|
Chris@0
|
606 * @param \Drupal\field\FieldStorageConfigInterface $field
|
Chris@0
|
607 * The field storage config entity.
|
Chris@0
|
608 *
|
Chris@0
|
609 * @see hook_field_views_data()
|
Chris@0
|
610 * @see hook_field_views_data_alter()
|
Chris@0
|
611 * @see views_views_data_alter()
|
Chris@0
|
612 */
|
Chris@0
|
613 function hook_field_views_data_views_data_alter(array &$data, \Drupal\field\FieldStorageConfigInterface $field) {
|
Chris@0
|
614 $field_name = $field->getName();
|
Chris@0
|
615 $data_key = 'field_data_' . $field_name;
|
Chris@0
|
616 $entity_type_id = $field->entity_type;
|
Chris@0
|
617 $entity_type = \Drupal::entityManager()->getDefinition($entity_type_id);
|
Chris@0
|
618 $pseudo_field_name = 'reverse_' . $field_name . '_' . $entity_type_id;
|
Chris@0
|
619 list($label) = views_entity_field_label($entity_type_id, $field_name);
|
Chris@0
|
620 $table_mapping = \Drupal::entityManager()->getStorage($entity_type_id)->getTableMapping();
|
Chris@0
|
621
|
Chris@0
|
622 // Views data for this field is in $data[$data_key].
|
Chris@0
|
623 $data[$data_key][$pseudo_field_name]['relationship'] = [
|
Chris@0
|
624 'title' => t('@entity using @field', ['@entity' => $entity_type->getLabel(), '@field' => $label]),
|
Chris@0
|
625 'help' => t('Relate each @entity with a @field set to the term.', ['@entity' => $entity_type->getLabel(), '@field' => $label]),
|
Chris@0
|
626 'id' => 'entity_reverse',
|
Chris@0
|
627 'field_name' => $field_name,
|
Chris@0
|
628 'entity_type' => $entity_type_id,
|
Chris@0
|
629 'field table' => $table_mapping->getDedicatedDataTableName($field),
|
Chris@0
|
630 'field field' => $field_name . '_target_id',
|
Chris@0
|
631 'base' => $entity_type->getBaseTable(),
|
Chris@0
|
632 'base field' => $entity_type->getKey('id'),
|
Chris@0
|
633 'label' => $field_name,
|
Chris@0
|
634 'join_extra' => [
|
Chris@0
|
635 0 => [
|
Chris@0
|
636 'field' => 'deleted',
|
Chris@0
|
637 'value' => 0,
|
Chris@0
|
638 'numeric' => TRUE,
|
Chris@0
|
639 ],
|
Chris@0
|
640 ],
|
Chris@0
|
641 ];
|
Chris@0
|
642 }
|
Chris@0
|
643
|
Chris@0
|
644 /**
|
Chris@0
|
645 * Replace special strings in the query before it is executed.
|
Chris@0
|
646 *
|
Chris@0
|
647 * The idea is that certain dynamic values can be placed in a query when it is
|
Chris@0
|
648 * built, and substituted at run-time, allowing the query to be cached and
|
Chris@0
|
649 * still work correctly when executed.
|
Chris@0
|
650 *
|
Chris@0
|
651 * @param \Drupal\views\ViewExecutable $view
|
Chris@0
|
652 * The View being executed.
|
Chris@0
|
653 *
|
Chris@0
|
654 * @return array
|
Chris@0
|
655 * An associative array where each key is a string to be replaced, and the
|
Chris@0
|
656 * corresponding value is its replacement. The strings to replace are often
|
Chris@0
|
657 * surrounded with '***', as illustrated in the example implementation, to
|
Chris@0
|
658 * avoid collisions with other values in the query.
|
Chris@0
|
659 */
|
Chris@0
|
660 function hook_views_query_substitutions(ViewExecutable $view) {
|
Chris@0
|
661 // Example from views_views_query_substitutions().
|
Chris@0
|
662 return [
|
Chris@0
|
663 '***CURRENT_VERSION***' => \Drupal::VERSION,
|
Chris@0
|
664 '***CURRENT_TIME***' => REQUEST_TIME,
|
Chris@0
|
665 '***LANGUAGE_language_content***' => \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId(),
|
Chris@0
|
666 PluginBase::VIEWS_QUERY_LANGUAGE_SITE_DEFAULT => \Drupal::languageManager()->getDefaultLanguage()->getId(),
|
Chris@0
|
667 ];
|
Chris@0
|
668 }
|
Chris@0
|
669
|
Chris@0
|
670 /**
|
Chris@0
|
671 * Replace special strings when processing a view with form elements.
|
Chris@0
|
672 *
|
Chris@0
|
673 * @return array
|
Chris@0
|
674 * An associative array where each key is a string to be replaced, and the
|
Chris@0
|
675 * corresponding value is its replacement. The value will be escaped unless it
|
Chris@0
|
676 * is already marked safe.
|
Chris@0
|
677 */
|
Chris@0
|
678 function hook_views_form_substitutions() {
|
Chris@0
|
679 return [
|
Chris@0
|
680 '<!--views-form-example-substitutions-->' => 'Example Substitution',
|
Chris@0
|
681 ];
|
Chris@0
|
682 }
|
Chris@0
|
683
|
Chris@0
|
684 /**
|
Chris@0
|
685 * Alter a view at the very beginning of Views processing.
|
Chris@0
|
686 *
|
Chris@0
|
687 * Output can be added to the view by setting $view->attachment_before
|
Chris@0
|
688 * and $view->attachment_after.
|
Chris@0
|
689 *
|
Chris@0
|
690 * @param \Drupal\views\ViewExecutable $view
|
Chris@0
|
691 * The view object about to be processed.
|
Chris@0
|
692 * @param string $display_id
|
Chris@0
|
693 * The machine name of the active display.
|
Chris@0
|
694 * @param array $args
|
Chris@0
|
695 * An array of arguments passed into the view.
|
Chris@0
|
696 *
|
Chris@0
|
697 * @see \Drupal\views\ViewExecutable
|
Chris@0
|
698 */
|
Chris@0
|
699 function hook_views_pre_view(ViewExecutable $view, $display_id, array &$args) {
|
Chris@0
|
700
|
Chris@0
|
701 // Modify contextual filters for my_special_view if user has 'my special permission'.
|
Chris@0
|
702 $account = \Drupal::currentUser();
|
Chris@0
|
703
|
Chris@0
|
704 if ($view->id() == 'my_special_view' && $account->hasPermission('my special permission') && $display_id == 'public_display') {
|
Chris@0
|
705 $args[0] = 'custom value';
|
Chris@0
|
706 }
|
Chris@0
|
707 }
|
Chris@0
|
708
|
Chris@0
|
709 /**
|
Chris@0
|
710 * Act on the view before the query is built, but after displays are attached.
|
Chris@0
|
711 *
|
Chris@0
|
712 * Output can be added to the view by setting $view->attachment_before
|
Chris@0
|
713 * and $view->attachment_after.
|
Chris@0
|
714 *
|
Chris@0
|
715 * @param \Drupal\views\ViewExecutable $view
|
Chris@0
|
716 * The view object about to be processed.
|
Chris@0
|
717 *
|
Chris@0
|
718 * @see \Drupal\views\ViewExecutable
|
Chris@0
|
719 */
|
Chris@0
|
720 function hook_views_pre_build(ViewExecutable $view) {
|
Chris@0
|
721 // Because of some inexplicable business logic, we should remove all
|
Chris@0
|
722 // attachments from all views on Mondays.
|
Chris@0
|
723 // (This alter could be done later in the execution process as well.)
|
Chris@0
|
724 if (date('D') == 'Mon') {
|
Chris@0
|
725 unset($view->attachment_before);
|
Chris@0
|
726 unset($view->attachment_after);
|
Chris@0
|
727 }
|
Chris@0
|
728 }
|
Chris@0
|
729
|
Chris@0
|
730 /**
|
Chris@0
|
731 * Act on the view immediately after the query is built.
|
Chris@0
|
732 *
|
Chris@0
|
733 * Output can be added to the view by setting $view->attachment_before
|
Chris@0
|
734 * and $view->attachment_after.
|
Chris@0
|
735 *
|
Chris@0
|
736 * @param \Drupal\views\ViewExecutable $view
|
Chris@0
|
737 * The view object about to be processed.
|
Chris@0
|
738 *
|
Chris@0
|
739 * @see \Drupal\views\ViewExecutable
|
Chris@0
|
740 */
|
Chris@0
|
741 function hook_views_post_build(ViewExecutable $view) {
|
Chris@0
|
742 // If the exposed field 'type' is set, hide the column containing the content
|
Chris@0
|
743 // type. (Note that this is a solution for a particular view, and makes
|
Chris@0
|
744 // assumptions about both exposed filter settings and the fields in the view.
|
Chris@0
|
745 // Also note that this alter could be done at any point before the view being
|
Chris@0
|
746 // rendered.)
|
Chris@0
|
747 if ($view->id() == 'my_view' && isset($view->exposed_raw_input['type']) && $view->exposed_raw_input['type'] != 'All') {
|
Chris@0
|
748 // 'Type' should be interpreted as content type.
|
Chris@0
|
749 if (isset($view->field['type'])) {
|
Chris@0
|
750 $view->field['type']->options['exclude'] = TRUE;
|
Chris@0
|
751 }
|
Chris@0
|
752 }
|
Chris@0
|
753 }
|
Chris@0
|
754
|
Chris@0
|
755 /**
|
Chris@0
|
756 * Act on the view after the query is built and just before it is executed.
|
Chris@0
|
757 *
|
Chris@0
|
758 * Output can be added to the view by setting $view->attachment_before
|
Chris@0
|
759 * and $view->attachment_after.
|
Chris@0
|
760 *
|
Chris@0
|
761 * @param \Drupal\views\ViewExecutable $view
|
Chris@0
|
762 * The view object about to be processed.
|
Chris@0
|
763 *
|
Chris@0
|
764 * @see \Drupal\views\ViewExecutable
|
Chris@0
|
765 */
|
Chris@0
|
766 function hook_views_pre_execute(ViewExecutable $view) {
|
Chris@0
|
767 // Whenever a view queries more than two tables, show a message that notifies
|
Chris@0
|
768 // view administrators that the query might be heavy.
|
Chris@0
|
769 // (This action could be performed later in the execution process, but not
|
Chris@0
|
770 // earlier.)
|
Chris@0
|
771 $account = \Drupal::currentUser();
|
Chris@0
|
772
|
Chris@0
|
773 if (count($view->query->tables) > 2 && $account->hasPermission('administer views')) {
|
Chris@17
|
774 \Drupal::messenger()->addWarning(t('The view %view may be heavy to execute.', ['%view' => $view->id()]));
|
Chris@0
|
775 }
|
Chris@0
|
776 }
|
Chris@0
|
777
|
Chris@0
|
778 /**
|
Chris@0
|
779 * Act on the view immediately after the query has been executed.
|
Chris@0
|
780 *
|
Chris@0
|
781 * At this point the query has been executed, but the preRender() phase has
|
Chris@0
|
782 * not yet happened for handlers.
|
Chris@0
|
783 *
|
Chris@0
|
784 * Output can be added to the view by setting $view->attachment_before
|
Chris@0
|
785 * and $view->attachment_after.
|
Chris@0
|
786 *
|
Chris@0
|
787 * @param \Drupal\views\ViewExecutable $view
|
Chris@0
|
788 * The view object about to be processed.
|
Chris@0
|
789 *
|
Chris@0
|
790 * @see \Drupal\views\ViewExecutable
|
Chris@0
|
791 */
|
Chris@0
|
792 function hook_views_post_execute(ViewExecutable $view) {
|
Chris@0
|
793 // If there are more than 100 results, show a message that encourages the user
|
Chris@0
|
794 // to change the filter settings.
|
Chris@0
|
795 // (This action could be performed later in the execution process, but not
|
Chris@0
|
796 // earlier.)
|
Chris@0
|
797 if ($view->total_rows > 100) {
|
Chris@17
|
798 \Drupal::messenger()->addStatus(t('You have more than 100 hits. Use the filter settings to narrow down your list.'));
|
Chris@0
|
799 }
|
Chris@0
|
800 }
|
Chris@0
|
801
|
Chris@0
|
802 /**
|
Chris@0
|
803 * Act on the view immediately before rendering it.
|
Chris@0
|
804 *
|
Chris@0
|
805 * At this point the query has been executed, and the preRender() phase has
|
Chris@0
|
806 * already happened for handlers, so all data should be available. This hook
|
Chris@0
|
807 * can be used by themes.
|
Chris@0
|
808 *
|
Chris@0
|
809 * Output can be added to the view by setting $view->attachment_before
|
Chris@0
|
810 * and $view->attachment_after.
|
Chris@0
|
811 *
|
Chris@0
|
812 * @param \Drupal\views\ViewExecutable $view
|
Chris@0
|
813 * The view object about to be processed.
|
Chris@0
|
814 *
|
Chris@0
|
815 * @see \Drupal\views\ViewExecutable
|
Chris@0
|
816 */
|
Chris@0
|
817 function hook_views_pre_render(ViewExecutable $view) {
|
Chris@0
|
818 // Scramble the order of the rows shown on this result page.
|
Chris@0
|
819 // Note that this could be done earlier, but not later in the view execution
|
Chris@0
|
820 // process.
|
Chris@0
|
821 shuffle($view->result);
|
Chris@0
|
822 }
|
Chris@0
|
823
|
Chris@0
|
824 /**
|
Chris@0
|
825 * Post-process any rendered data.
|
Chris@0
|
826 *
|
Chris@0
|
827 * This can be valuable to be able to cache a view and still have some level of
|
Chris@0
|
828 * dynamic output. In an ideal world, the actual output will include HTML
|
Chris@0
|
829 * comment-based tokens, and then the post process can replace those tokens.
|
Chris@0
|
830 * This hook can be used by themes.
|
Chris@0
|
831 *
|
Chris@0
|
832 * Example usage. If it is known that the view is a node view and that the
|
Chris@0
|
833 * primary field will be a nid, you can do something like this:
|
Chris@0
|
834 * @code
|
Chris@0
|
835 * <!--post-FIELD-NID-->
|
Chris@0
|
836 * @endcode
|
Chris@0
|
837 * And then in the post-render, create an array with the text that should
|
Chris@0
|
838 * go there:
|
Chris@0
|
839 * @code
|
Chris@0
|
840 * strtr($output, array('<!--post-FIELD-1-->' => 'output for FIELD of nid 1');
|
Chris@0
|
841 * @endcode
|
Chris@0
|
842 * All of the cached result data will be available in $view->result, as well,
|
Chris@0
|
843 * so all ids used in the query should be discoverable.
|
Chris@0
|
844 *
|
Chris@0
|
845 * @param \Drupal\views\ViewExecutable $view
|
Chris@0
|
846 * The view object about to be processed.
|
Chris@0
|
847 * @param string $output
|
Chris@0
|
848 * A flat string with the rendered output of the view.
|
Chris@0
|
849 * @param \Drupal\views\Plugin\views\cache\CachePluginBase $cache
|
Chris@0
|
850 * The cache settings.
|
Chris@0
|
851 *
|
Chris@0
|
852 * @see \Drupal\views\ViewExecutable
|
Chris@0
|
853 */
|
Chris@0
|
854 function hook_views_post_render(ViewExecutable $view, &$output, CachePluginBase $cache) {
|
Chris@0
|
855 // When using full pager, disable any time-based caching if there are fewer
|
Chris@0
|
856 // than 10 results.
|
Chris@0
|
857 if ($view->pager instanceof Drupal\views\Plugin\views\pager\Full && $cache instanceof Drupal\views\Plugin\views\cache\Time && count($view->result) < 10) {
|
Chris@0
|
858 $cache->options['results_lifespan'] = 0;
|
Chris@0
|
859 $cache->options['output_lifespan'] = 0;
|
Chris@0
|
860 }
|
Chris@0
|
861 }
|
Chris@0
|
862
|
Chris@0
|
863 /**
|
Chris@0
|
864 * Alter the query before it is executed.
|
Chris@0
|
865 *
|
Chris@0
|
866 * @param \Drupal\views\ViewExecutable $view
|
Chris@0
|
867 * The view object about to be processed.
|
Chris@0
|
868 * @param QueryPluginBase $query
|
Chris@0
|
869 * The query plugin object for the query.
|
Chris@0
|
870 *
|
Chris@0
|
871 * @see hook_views_query_substitutions()
|
Chris@0
|
872 * @see \Drupal\views\Plugin\views\query\Sql
|
Chris@0
|
873 */
|
Chris@0
|
874 function hook_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {
|
Chris@0
|
875 // (Example assuming a view with an exposed filter on node title.)
|
Chris@0
|
876 // If the input for the title filter is a positive integer, filter against
|
Chris@0
|
877 // node ID instead of node title.
|
Chris@0
|
878 if ($view->id() == 'my_view' && is_numeric($view->exposed_raw_input['title']) && $view->exposed_raw_input['title'] > 0) {
|
Chris@0
|
879 // Traverse through the 'where' part of the query.
|
Chris@0
|
880 foreach ($query->where as &$condition_group) {
|
Chris@0
|
881 foreach ($condition_group['conditions'] as &$condition) {
|
Chris@0
|
882 // If this is the part of the query filtering on title, chang the
|
Chris@0
|
883 // condition to filter on node ID.
|
Chris@0
|
884 if ($condition['field'] == 'node.title') {
|
Chris@0
|
885 $condition = [
|
Chris@0
|
886 'field' => 'node.nid',
|
Chris@0
|
887 'value' => $view->exposed_raw_input['title'],
|
Chris@0
|
888 'operator' => '=',
|
Chris@0
|
889 ];
|
Chris@0
|
890 }
|
Chris@0
|
891 }
|
Chris@0
|
892 }
|
Chris@0
|
893 }
|
Chris@0
|
894 }
|
Chris@0
|
895
|
Chris@0
|
896 /**
|
Chris@0
|
897 * Alter the view preview information.
|
Chris@0
|
898 *
|
Chris@0
|
899 * The view preview information is optionally displayed when a view is
|
Chris@0
|
900 * previewed in the administrative UI. It includes query and performance
|
Chris@0
|
901 * statistics.
|
Chris@0
|
902 *
|
Chris@0
|
903 * @param array $rows
|
Chris@0
|
904 * An associative array with two keys:
|
Chris@0
|
905 * - query: An array of rows suitable for '#type' => 'table', containing
|
Chris@0
|
906 * information about the query and the display title and path.
|
Chris@0
|
907 * - statistics: An array of rows suitable for '#type' => 'table',
|
Chris@0
|
908 * containing performance statistics.
|
Chris@0
|
909 * @param \Drupal\views\ViewExecutable $view
|
Chris@0
|
910 * The view object.
|
Chris@0
|
911 *
|
Chris@0
|
912 * @see \Drupal\views_ui\ViewUI
|
Chris@0
|
913 * @see table.html.twig
|
Chris@0
|
914 */
|
Chris@0
|
915 function hook_views_preview_info_alter(array &$rows, ViewExecutable $view) {
|
Chris@0
|
916 // Adds information about the tables being queried by the view to the query
|
Chris@0
|
917 // part of the info box.
|
Chris@0
|
918 $rows['query'][] = [
|
Chris@0
|
919 t('<strong>Table queue</strong>'),
|
Chris@0
|
920 count($view->query->table_queue) . ': (' . implode(', ', array_keys($view->query->table_queue)) . ')',
|
Chris@0
|
921 ];
|
Chris@0
|
922 }
|
Chris@0
|
923
|
Chris@0
|
924 /**
|
Chris@0
|
925 * Alter the links displayed at the top of the view edit form.
|
Chris@0
|
926 *
|
Chris@0
|
927 * @param array $links
|
Chris@0
|
928 * A renderable array of links which will be displayed at the top of the
|
Chris@0
|
929 * view edit form. Each entry will be in a form suitable for
|
Chris@0
|
930 * '#theme' => 'links'.
|
Chris@0
|
931 * @param \Drupal\views\ViewExecutable $view
|
Chris@0
|
932 * The view object being edited.
|
Chris@0
|
933 * @param string $display_id
|
Chris@0
|
934 * The ID of the display being edited, e.g. 'default' or 'page_1'.
|
Chris@0
|
935 *
|
Chris@0
|
936 * @see \Drupal\views_ui\ViewUI::renderDisplayTop()
|
Chris@0
|
937 */
|
Chris@0
|
938 function hook_views_ui_display_top_links_alter(array &$links, ViewExecutable $view, $display_id) {
|
Chris@0
|
939 // Put the export link first in the list.
|
Chris@0
|
940 if (isset($links['export'])) {
|
Chris@0
|
941 $links = ['export' => $links['export']] + $links;
|
Chris@0
|
942 }
|
Chris@0
|
943 }
|
Chris@0
|
944
|
Chris@0
|
945 // @todo Describe how to alter a view ajax response with event listeners.
|
Chris@0
|
946
|
Chris@0
|
947 /**
|
Chris@0
|
948 * Allow modules to respond to the invalidation of the Views cache.
|
Chris@0
|
949 *
|
Chris@0
|
950 * This hook will fire whenever a view is enabled, disabled, created,
|
Chris@0
|
951 * updated, or deleted.
|
Chris@0
|
952 *
|
Chris@0
|
953 * @see views_invalidate_cache()
|
Chris@0
|
954 */
|
Chris@0
|
955 function hook_views_invalidate_cache() {
|
Chris@0
|
956 \Drupal\Core\Cache\Cache::invalidateTags(['views']);
|
Chris@0
|
957 }
|
Chris@0
|
958
|
Chris@0
|
959 /**
|
Chris@0
|
960 * Modify the list of available views access plugins.
|
Chris@0
|
961 *
|
Chris@0
|
962 * This hook may be used to modify plugin properties after they have been
|
Chris@0
|
963 * specified by other modules.
|
Chris@0
|
964 *
|
Chris@0
|
965 * @param array $plugins
|
Chris@0
|
966 * An array of all the existing plugin definitions, passed by reference.
|
Chris@0
|
967 *
|
Chris@0
|
968 * @see \Drupal\views\Plugin\ViewsPluginManager
|
Chris@0
|
969 */
|
Chris@0
|
970 function hook_views_plugins_access_alter(array &$plugins) {
|
Chris@0
|
971 // Remove the available plugin because the users should not have access to it.
|
Chris@0
|
972 unset($plugins['role']);
|
Chris@0
|
973 }
|
Chris@0
|
974
|
Chris@0
|
975 /**
|
Chris@0
|
976 * Modify the list of available views default argument plugins.
|
Chris@0
|
977 *
|
Chris@0
|
978 * This hook may be used to modify plugin properties after they have been
|
Chris@0
|
979 * specified by other modules.
|
Chris@0
|
980 *
|
Chris@0
|
981 * @param array $plugins
|
Chris@0
|
982 * An array of all the existing plugin definitions, passed by reference.
|
Chris@0
|
983 *
|
Chris@0
|
984 * @see \Drupal\views\Plugin\ViewsPluginManager
|
Chris@0
|
985 */
|
Chris@0
|
986 function hook_views_plugins_argument_default_alter(array &$plugins) {
|
Chris@0
|
987 // Remove the available plugin because the users should not have access to it.
|
Chris@0
|
988 unset($plugins['php']);
|
Chris@0
|
989 }
|
Chris@0
|
990
|
Chris@0
|
991 /**
|
Chris@0
|
992 * Modify the list of available views argument validation plugins.
|
Chris@0
|
993 *
|
Chris@0
|
994 * This hook may be used to modify plugin properties after they have been
|
Chris@0
|
995 * specified by other modules.
|
Chris@0
|
996 *
|
Chris@0
|
997 * @param array $plugins
|
Chris@0
|
998 * An array of all the existing plugin definitions, passed by reference.
|
Chris@0
|
999 *
|
Chris@0
|
1000 * @see \Drupal\views\Plugin\ViewsPluginManager
|
Chris@0
|
1001 */
|
Chris@0
|
1002 function hook_views_plugins_argument_validator_alter(array &$plugins) {
|
Chris@0
|
1003 // Remove the available plugin because the users should not have access to it.
|
Chris@0
|
1004 unset($plugins['php']);
|
Chris@0
|
1005 }
|
Chris@0
|
1006
|
Chris@0
|
1007 /**
|
Chris@0
|
1008 * Modify the list of available views cache plugins.
|
Chris@0
|
1009 *
|
Chris@0
|
1010 * This hook may be used to modify plugin properties after they have been
|
Chris@0
|
1011 * specified by other modules.
|
Chris@0
|
1012 *
|
Chris@0
|
1013 * @param array $plugins
|
Chris@0
|
1014 * An array of all the existing plugin definitions, passed by reference.
|
Chris@0
|
1015 *
|
Chris@0
|
1016 * @see \Drupal\views\Plugin\ViewsPluginManager
|
Chris@0
|
1017 */
|
Chris@0
|
1018 function hook_views_plugins_cache_alter(array &$plugins) {
|
Chris@0
|
1019 // Change the title.
|
Chris@0
|
1020 $plugins['time']['title'] = t('Custom title');
|
Chris@0
|
1021 }
|
Chris@0
|
1022
|
Chris@0
|
1023 /**
|
Chris@0
|
1024 * Modify the list of available views display extender plugins.
|
Chris@0
|
1025 *
|
Chris@0
|
1026 * This hook may be used to modify plugin properties after they have been
|
Chris@0
|
1027 * specified by other modules.
|
Chris@0
|
1028 *
|
Chris@0
|
1029 * @param array $plugins
|
Chris@0
|
1030 * An array of all the existing plugin definitions, passed by reference.
|
Chris@0
|
1031 *
|
Chris@0
|
1032 * @see \Drupal\views\Plugin\ViewsPluginManager
|
Chris@0
|
1033 */
|
Chris@0
|
1034 function hook_views_plugins_display_extenders_alter(array &$plugins) {
|
Chris@0
|
1035 // Alter the title of an existing plugin.
|
Chris@0
|
1036 $plugins['time']['title'] = t('Custom title');
|
Chris@0
|
1037 }
|
Chris@0
|
1038
|
Chris@0
|
1039 /**
|
Chris@0
|
1040 * Modify the list of available views display plugins.
|
Chris@0
|
1041 *
|
Chris@0
|
1042 * This hook may be used to modify plugin properties after they have been
|
Chris@0
|
1043 * specified by other modules.
|
Chris@0
|
1044 *
|
Chris@0
|
1045 * @param array $plugins
|
Chris@0
|
1046 * An array of all the existing plugin definitions, passed by reference.
|
Chris@0
|
1047 *
|
Chris@0
|
1048 * @see \Drupal\views\Plugin\ViewsPluginManager
|
Chris@0
|
1049 */
|
Chris@0
|
1050 function hook_views_plugins_display_alter(array &$plugins) {
|
Chris@0
|
1051 // Alter the title of an existing plugin.
|
Chris@0
|
1052 $plugins['rest_export']['title'] = t('Export');
|
Chris@0
|
1053 }
|
Chris@0
|
1054
|
Chris@0
|
1055 /**
|
Chris@0
|
1056 * Modify the list of available views exposed form plugins.
|
Chris@0
|
1057 *
|
Chris@0
|
1058 * This hook may be used to modify plugin properties after they have been
|
Chris@0
|
1059 * specified by other modules.
|
Chris@0
|
1060 *
|
Chris@0
|
1061 * @param array $plugins
|
Chris@0
|
1062 * An array of all the existing plugin definitions, passed by reference.
|
Chris@0
|
1063 *
|
Chris@0
|
1064 * @see \Drupal\views\Plugin\ViewsPluginManager
|
Chris@0
|
1065 */
|
Chris@0
|
1066 function hook_views_plugins_exposed_form_alter(array &$plugins) {
|
Chris@0
|
1067 // Remove the available plugin because the users should not have access to it.
|
Chris@0
|
1068 unset($plugins['input_required']);
|
Chris@0
|
1069 }
|
Chris@0
|
1070
|
Chris@0
|
1071 /**
|
Chris@0
|
1072 * Modify the list of available views join plugins.
|
Chris@0
|
1073 *
|
Chris@0
|
1074 * This hook may be used to modify plugin properties after they have been
|
Chris@0
|
1075 * specified by other modules.
|
Chris@0
|
1076 *
|
Chris@0
|
1077 * @param array $plugins
|
Chris@0
|
1078 * An array of all the existing plugin definitions, passed by reference.
|
Chris@0
|
1079 *
|
Chris@0
|
1080 * @see \Drupal\views\Plugin\ViewsPluginManager
|
Chris@0
|
1081 */
|
Chris@0
|
1082 function hook_views_plugins_join_alter(array &$plugins) {
|
Chris@0
|
1083 // Print out all join plugin names for debugging purposes.
|
Chris@0
|
1084 debug($plugins);
|
Chris@0
|
1085 }
|
Chris@0
|
1086
|
Chris@0
|
1087 /**
|
Chris@0
|
1088 * Modify the list of available views pager plugins.
|
Chris@0
|
1089 *
|
Chris@0
|
1090 * This hook may be used to modify plugin properties after they have been
|
Chris@0
|
1091 * specified by other modules.
|
Chris@0
|
1092 *
|
Chris@0
|
1093 * @param array $plugins
|
Chris@0
|
1094 * An array of all the existing plugin definitions, passed by reference.
|
Chris@0
|
1095 *
|
Chris@0
|
1096 * @see \Drupal\views\Plugin\ViewsPluginManager
|
Chris@0
|
1097 */
|
Chris@0
|
1098 function hook_views_plugins_pager_alter(array &$plugins) {
|
Chris@0
|
1099 // Remove the sql based plugin to force good performance.
|
Chris@0
|
1100 unset($plugins['full']);
|
Chris@0
|
1101 }
|
Chris@0
|
1102
|
Chris@0
|
1103 /**
|
Chris@0
|
1104 * Modify the list of available views query plugins.
|
Chris@0
|
1105 *
|
Chris@0
|
1106 * This hook may be used to modify plugin properties after they have been
|
Chris@0
|
1107 * specified by other modules.
|
Chris@0
|
1108 *
|
Chris@0
|
1109 * @param array $plugins
|
Chris@0
|
1110 * An array of all the existing plugin definitions, passed by reference.
|
Chris@0
|
1111 *
|
Chris@0
|
1112 * @see \Drupal\views\Plugin\ViewsPluginManager
|
Chris@0
|
1113 */
|
Chris@0
|
1114 function hook_views_plugins_query_alter(array &$plugins) {
|
Chris@0
|
1115 // Print out all query plugin names for debugging purposes.
|
Chris@0
|
1116 debug($plugins);
|
Chris@0
|
1117 }
|
Chris@0
|
1118
|
Chris@0
|
1119 /**
|
Chris@0
|
1120 * Modify the list of available views row plugins.
|
Chris@0
|
1121 *
|
Chris@0
|
1122 * This hook may be used to modify plugin properties after they have been
|
Chris@0
|
1123 * specified by other modules.
|
Chris@0
|
1124 *
|
Chris@0
|
1125 * @param array $plugins
|
Chris@0
|
1126 * An array of all the existing plugin definitions, passed by reference.
|
Chris@0
|
1127 *
|
Chris@0
|
1128 * @see \Drupal\views\Plugin\ViewsPluginManager
|
Chris@0
|
1129 */
|
Chris@0
|
1130 function hook_views_plugins_row_alter(array &$plugins) {
|
Chris@0
|
1131 // Change the used class of a plugin.
|
Chris@0
|
1132 $plugins['entity:node']['class'] = 'Drupal\node\Plugin\views\row\NodeRow';
|
Chris@0
|
1133 $plugins['entity:node']['module'] = 'node';
|
Chris@0
|
1134 }
|
Chris@0
|
1135
|
Chris@0
|
1136 /**
|
Chris@0
|
1137 * Modify the list of available views style plugins.
|
Chris@0
|
1138 *
|
Chris@0
|
1139 * This hook may be used to modify plugin properties after they have been
|
Chris@0
|
1140 * specified by other modules.
|
Chris@0
|
1141 *
|
Chris@0
|
1142 * @param array $plugins
|
Chris@0
|
1143 * An array of all the existing plugin definitions, passed by reference.
|
Chris@0
|
1144 *
|
Chris@0
|
1145 * @see \Drupal\views\Plugin\ViewsPluginManager
|
Chris@0
|
1146 */
|
Chris@0
|
1147 function hook_views_plugins_style_alter(array &$plugins) {
|
Chris@0
|
1148 // Change the theme hook of a plugin.
|
Chris@0
|
1149 $plugins['html_list']['theme'] = 'custom_views_view_list';
|
Chris@0
|
1150 }
|
Chris@0
|
1151
|
Chris@0
|
1152 /**
|
Chris@0
|
1153 * Modify the list of available views wizard plugins.
|
Chris@0
|
1154 *
|
Chris@0
|
1155 * This hook may be used to modify plugin properties after they have been
|
Chris@0
|
1156 * specified by other modules.
|
Chris@0
|
1157 *
|
Chris@0
|
1158 * @param array $plugins
|
Chris@0
|
1159 * An array of all the existing plugin definitions, passed by reference.
|
Chris@0
|
1160 *
|
Chris@0
|
1161 * @see \Drupal\views\Plugin\ViewsPluginManager
|
Chris@0
|
1162 */
|
Chris@0
|
1163 function hook_views_plugins_wizard_alter(array &$plugins) {
|
Chris@0
|
1164 // Change the title of a plugin.
|
Chris@0
|
1165 $plugins['node_revision']['title'] = t('Node revision wizard');
|
Chris@0
|
1166 }
|
Chris@0
|
1167
|
Chris@0
|
1168 /**
|
Chris@0
|
1169 * Modify the list of available views area handler plugins.
|
Chris@0
|
1170 *
|
Chris@0
|
1171 * This hook may be used to modify handler properties after they have been
|
Chris@0
|
1172 * specified by other modules.
|
Chris@0
|
1173 *
|
Chris@0
|
1174 * @param array $plugins
|
Chris@0
|
1175 * An array of all the existing handler definitions, passed by reference.
|
Chris@0
|
1176 *
|
Chris@0
|
1177 * @see \Drupal\views\Plugin\ViewsHandlerManager
|
Chris@0
|
1178 */
|
Chris@0
|
1179 function hook_views_plugins_area_alter(array &$plugins) {
|
Chris@0
|
1180 // Change the 'title' handler class.
|
Chris@0
|
1181 $plugins['title']['class'] = 'Drupal\\example\\ExampleClass';
|
Chris@0
|
1182 }
|
Chris@0
|
1183
|
Chris@0
|
1184 /**
|
Chris@0
|
1185 * Modify the list of available views argument handler plugins.
|
Chris@0
|
1186 *
|
Chris@0
|
1187 * This hook may be used to modify handler properties after they have been
|
Chris@0
|
1188 * specified by other modules.
|
Chris@0
|
1189 *
|
Chris@0
|
1190 * @param array $plugins
|
Chris@0
|
1191 * An array of all the existing handler definitions, passed by reference.
|
Chris@0
|
1192 *
|
Chris@0
|
1193 * @see \Drupal\views\Plugin\ViewsHandlerManager
|
Chris@0
|
1194 */
|
Chris@0
|
1195 function hook_views_plugins_argument_alter(array &$plugins) {
|
Chris@0
|
1196 // Change the 'title' handler class.
|
Chris@0
|
1197 $plugins['title']['class'] = 'Drupal\\example\\ExampleClass';
|
Chris@0
|
1198 }
|
Chris@0
|
1199
|
Chris@0
|
1200 /**
|
Chris@0
|
1201 * Modify the list of available views field handler plugins.
|
Chris@0
|
1202 *
|
Chris@0
|
1203 * This hook may be used to modify handler properties after they have been
|
Chris@0
|
1204 * specified by other modules.
|
Chris@0
|
1205 *
|
Chris@0
|
1206 * @param array $plugins
|
Chris@0
|
1207 * An array of all the existing handler definitions, passed by reference.
|
Chris@0
|
1208 *
|
Chris@0
|
1209 * @see \Drupal\views\Plugin\ViewsHandlerManager
|
Chris@0
|
1210 */
|
Chris@0
|
1211 function hook_views_plugins_field_alter(array &$plugins) {
|
Chris@0
|
1212 // Change the 'title' handler class.
|
Chris@0
|
1213 $plugins['title']['class'] = 'Drupal\\example\\ExampleClass';
|
Chris@0
|
1214 }
|
Chris@0
|
1215
|
Chris@0
|
1216 /**
|
Chris@0
|
1217 * Modify the list of available views filter handler plugins.
|
Chris@0
|
1218 *
|
Chris@0
|
1219 * This hook may be used to modify handler properties after they have been
|
Chris@0
|
1220 * specified by other modules.
|
Chris@0
|
1221 *
|
Chris@0
|
1222 * @param array $plugins
|
Chris@0
|
1223 * An array of all the existing handler definitions, passed by reference.
|
Chris@0
|
1224 *
|
Chris@0
|
1225 * @see \Drupal\views\Plugin\ViewsHandlerManager
|
Chris@0
|
1226 */
|
Chris@0
|
1227 function hook_views_plugins_filter_alter(array &$plugins) {
|
Chris@0
|
1228 // Change the 'title' handler class.
|
Chris@0
|
1229 $plugins['title']['class'] = 'Drupal\\example\\ExampleClass';
|
Chris@0
|
1230 }
|
Chris@0
|
1231
|
Chris@0
|
1232 /**
|
Chris@0
|
1233 * Modify the list of available views relationship handler plugins.
|
Chris@0
|
1234 *
|
Chris@0
|
1235 * This hook may be used to modify handler properties after they have been
|
Chris@0
|
1236 * specified by other modules.
|
Chris@0
|
1237 *
|
Chris@0
|
1238 * @param array $plugins
|
Chris@0
|
1239 * An array of all the existing handler definitions, passed by reference.
|
Chris@0
|
1240 *
|
Chris@0
|
1241 * @see \Drupal\views\Plugin\ViewsHandlerManager
|
Chris@0
|
1242 */
|
Chris@0
|
1243 function hook_views_plugins_relationship_alter(array &$plugins) {
|
Chris@0
|
1244 // Change the 'title' handler class.
|
Chris@0
|
1245 $plugins['title']['class'] = 'Drupal\\example\\ExampleClass';
|
Chris@0
|
1246 }
|
Chris@0
|
1247
|
Chris@0
|
1248 /**
|
Chris@0
|
1249 * Modify the list of available views sort handler plugins.
|
Chris@0
|
1250 *
|
Chris@0
|
1251 * This hook may be used to modify handler properties after they have been
|
Chris@0
|
1252 * specified by other modules.
|
Chris@0
|
1253 *
|
Chris@0
|
1254 * @param array $plugins
|
Chris@0
|
1255 * An array of all the existing handler definitions, passed by reference.
|
Chris@0
|
1256 *
|
Chris@0
|
1257 * @see \Drupal\views\Plugin\ViewsHandlerManager
|
Chris@0
|
1258 */
|
Chris@0
|
1259 function hook_views_plugins_sort_alter(array &$plugins) {
|
Chris@0
|
1260 // Change the 'title' handler class.
|
Chris@0
|
1261 $plugins['title']['class'] = 'Drupal\\example\\ExampleClass';
|
Chris@0
|
1262 }
|
Chris@0
|
1263
|
Chris@0
|
1264 /**
|
Chris@0
|
1265 * @} End of "addtogroup hooks".
|
Chris@0
|
1266 */
|
Chris@0
|
1267
|
Chris@0
|
1268 /**
|
Chris@0
|
1269 * @}
|
Chris@0
|
1270 */
|