views.api.php 44 KB

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