Mercurial > hg > isophonics-drupal-site
comparison core/modules/taxonomy/taxonomy.views.inc @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 /** | |
4 * @file | |
5 * Provides views data for taxonomy.module. | |
6 */ | |
7 | |
8 use Drupal\field\FieldStorageConfigInterface; | |
9 | |
10 /** | |
11 * Implements hook_views_data_alter(). | |
12 */ | |
13 function taxonomy_views_data_alter(&$data) { | |
14 $data['node_field_data']['term_node_tid'] = [ | |
15 'title' => t('Taxonomy terms on node'), | |
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.'), | |
17 'relationship' => [ | |
18 'id' => 'node_term_data', | |
19 'label' => t('term'), | |
20 'base' => 'taxonomy_term_field_data', | |
21 ], | |
22 'field' => [ | |
23 'title' => t('All taxonomy terms'), | |
24 'help' => t('Display all taxonomy terms associated with a node from specified vocabularies.'), | |
25 'id' => 'taxonomy_index_tid', | |
26 'no group by' => TRUE, | |
27 'click sortable' => FALSE, | |
28 ], | |
29 ]; | |
30 | |
31 $data['node_field_data']['term_node_tid_depth'] = [ | |
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.'), | |
33 'real field' => 'nid', | |
34 'argument' => [ | |
35 'title' => t('Has taxonomy term ID (with depth)'), | |
36 'id' => 'taxonomy_index_tid_depth', | |
37 'accept depth modifier' => TRUE, | |
38 ], | |
39 'filter' => [ | |
40 'title' => t('Has taxonomy terms (with depth)'), | |
41 'id' => 'taxonomy_index_tid_depth', | |
42 ], | |
43 ]; | |
44 | |
45 $data['node_field_data']['term_node_tid_depth_modifier'] = [ | |
46 'title' => t('Has taxonomy term ID depth modifier'), | |
47 'help' => t('Allows the "depth" for Taxonomy: Term ID (with depth) to be modified via an additional contextual filter value.'), | |
48 'argument' => [ | |
49 'id' => 'taxonomy_index_tid_depth_modifier', | |
50 ], | |
51 ]; | |
52 } | |
53 | |
54 /** | |
55 * Implements hook_field_views_data_alter(). | |
56 * | |
57 * Views integration for entity reference fields which reference taxonomy terms. | |
58 * Adds a term relationship to the default field data. | |
59 * | |
60 * @see views_field_default_views_data() | |
61 */ | |
62 function taxonomy_field_views_data_alter(array &$data, FieldStorageConfigInterface $field_storage) { | |
63 if ($field_storage->getType() == 'entity_reference' && $field_storage->getSetting('target_type') == 'taxonomy_term') { | |
64 foreach ($data as $table_name => $table_data) { | |
65 foreach ($table_data as $field_name => $field_data) { | |
66 if (isset($field_data['filter']) && $field_name != 'delta') { | |
67 $data[$table_name][$field_name]['filter']['id'] = 'taxonomy_index_tid'; | |
68 } | |
69 } | |
70 } | |
71 } | |
72 } | |
73 | |
74 /** | |
75 * Implements hook_views_plugins_argument_validator_alter(). | |
76 * | |
77 * Extend the generic entity argument validator. | |
78 * | |
79 * @see \Drupal\views\Plugin\views\argument_validator\Entity | |
80 */ | |
81 function taxonomy_views_plugins_argument_validator_alter(array &$plugins) { | |
82 $plugins['entity:taxonomy_term']['title'] = t('Taxonomy term ID'); | |
83 $plugins['entity:taxonomy_term']['class'] = 'Drupal\taxonomy\Plugin\views\argument_validator\Term'; | |
84 $plugins['entity:taxonomy_term']['provider'] = 'taxonomy'; | |
85 } |