Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /**
|
Chris@0
|
4 * @file
|
Chris@0
|
5 * Provides views data for taxonomy.module.
|
Chris@0
|
6 */
|
Chris@0
|
7
|
Chris@0
|
8 use Drupal\field\FieldStorageConfigInterface;
|
Chris@0
|
9
|
Chris@0
|
10 /**
|
Chris@0
|
11 * Implements hook_views_data_alter().
|
Chris@0
|
12 */
|
Chris@0
|
13 function taxonomy_views_data_alter(&$data) {
|
Chris@0
|
14 $data['node_field_data']['term_node_tid'] = [
|
Chris@0
|
15 'title' => t('Taxonomy terms on node'),
|
Chris@0
|
16 'help' => t('Relate nodes to taxonomy terms, specifying which vocabulary or vocabularies to use. This relationship will cause duplicated records if there are multiple terms.'),
|
Chris@0
|
17 'relationship' => [
|
Chris@0
|
18 'id' => 'node_term_data',
|
Chris@0
|
19 'label' => t('term'),
|
Chris@0
|
20 'base' => 'taxonomy_term_field_data',
|
Chris@0
|
21 ],
|
Chris@0
|
22 'field' => [
|
Chris@0
|
23 'title' => t('All taxonomy terms'),
|
Chris@0
|
24 'help' => t('Display all taxonomy terms associated with a node from specified vocabularies.'),
|
Chris@0
|
25 'id' => 'taxonomy_index_tid',
|
Chris@0
|
26 'no group by' => TRUE,
|
Chris@0
|
27 'click sortable' => FALSE,
|
Chris@0
|
28 ],
|
Chris@0
|
29 ];
|
Chris@0
|
30
|
Chris@0
|
31 $data['node_field_data']['term_node_tid_depth'] = [
|
Chris@0
|
32 'help' => t('Display content if it has the selected taxonomy terms, or children of the selected terms. Due to additional complexity, this has fewer options than the versions without depth.'),
|
Chris@0
|
33 'real field' => 'nid',
|
Chris@0
|
34 'argument' => [
|
Chris@0
|
35 'title' => t('Has taxonomy term ID (with depth)'),
|
Chris@0
|
36 'id' => 'taxonomy_index_tid_depth',
|
Chris@0
|
37 'accept depth modifier' => TRUE,
|
Chris@0
|
38 ],
|
Chris@0
|
39 'filter' => [
|
Chris@0
|
40 'title' => t('Has taxonomy terms (with depth)'),
|
Chris@0
|
41 'id' => 'taxonomy_index_tid_depth',
|
Chris@0
|
42 ],
|
Chris@0
|
43 ];
|
Chris@0
|
44
|
Chris@0
|
45 $data['node_field_data']['term_node_tid_depth_modifier'] = [
|
Chris@0
|
46 'title' => t('Has taxonomy term ID depth modifier'),
|
Chris@0
|
47 'help' => t('Allows the "depth" for Taxonomy: Term ID (with depth) to be modified via an additional contextual filter value.'),
|
Chris@0
|
48 'argument' => [
|
Chris@0
|
49 'id' => 'taxonomy_index_tid_depth_modifier',
|
Chris@0
|
50 ],
|
Chris@0
|
51 ];
|
Chris@0
|
52 }
|
Chris@0
|
53
|
Chris@0
|
54 /**
|
Chris@0
|
55 * Implements hook_field_views_data_alter().
|
Chris@0
|
56 *
|
Chris@0
|
57 * Views integration for entity reference fields which reference taxonomy terms.
|
Chris@0
|
58 * Adds a term relationship to the default field data.
|
Chris@0
|
59 *
|
Chris@0
|
60 * @see views_field_default_views_data()
|
Chris@0
|
61 */
|
Chris@0
|
62 function taxonomy_field_views_data_alter(array &$data, FieldStorageConfigInterface $field_storage) {
|
Chris@0
|
63 if ($field_storage->getType() == 'entity_reference' && $field_storage->getSetting('target_type') == 'taxonomy_term') {
|
Chris@0
|
64 foreach ($data as $table_name => $table_data) {
|
Chris@0
|
65 foreach ($table_data as $field_name => $field_data) {
|
Chris@0
|
66 if (isset($field_data['filter']) && $field_name != 'delta') {
|
Chris@0
|
67 $data[$table_name][$field_name]['filter']['id'] = 'taxonomy_index_tid';
|
Chris@0
|
68 }
|
Chris@0
|
69 }
|
Chris@0
|
70 }
|
Chris@0
|
71 }
|
Chris@0
|
72 }
|
Chris@0
|
73
|
Chris@0
|
74 /**
|
Chris@0
|
75 * Implements hook_views_plugins_argument_validator_alter().
|
Chris@0
|
76 *
|
Chris@0
|
77 * Extend the generic entity argument validator.
|
Chris@0
|
78 *
|
Chris@0
|
79 * @see \Drupal\views\Plugin\views\argument_validator\Entity
|
Chris@0
|
80 */
|
Chris@0
|
81 function taxonomy_views_plugins_argument_validator_alter(array &$plugins) {
|
Chris@0
|
82 $plugins['entity:taxonomy_term']['title'] = t('Taxonomy term ID');
|
Chris@0
|
83 $plugins['entity:taxonomy_term']['class'] = 'Drupal\taxonomy\Plugin\views\argument_validator\Term';
|
Chris@0
|
84 $plugins['entity:taxonomy_term']['provider'] = 'taxonomy';
|
Chris@0
|
85 }
|