annotate core/modules/taxonomy/src/TermViewsData.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\taxonomy;
Chris@0 4
Chris@0 5 use Drupal\views\EntityViewsData;
Chris@0 6
Chris@0 7 /**
Chris@0 8 * Provides the views data for the taxonomy entity type.
Chris@0 9 */
Chris@0 10 class TermViewsData extends EntityViewsData {
Chris@0 11
Chris@0 12 /**
Chris@0 13 * {@inheritdoc}
Chris@0 14 */
Chris@0 15 public function getViewsData() {
Chris@0 16 $data = parent::getViewsData();
Chris@0 17
Chris@0 18 $data['taxonomy_term_field_data']['table']['base']['help'] = $this->t('Taxonomy terms are attached to nodes.');
Chris@0 19 $data['taxonomy_term_field_data']['table']['base']['access query tag'] = 'taxonomy_term_access';
Chris@0 20 $data['taxonomy_term_field_data']['table']['wizard_id'] = 'taxonomy_term';
Chris@0 21
Chris@0 22 $data['taxonomy_term_field_data']['table']['join'] = [
Chris@0 23 // This is provided for the many_to_one argument.
Chris@0 24 'taxonomy_index' => [
Chris@0 25 'field' => 'tid',
Chris@0 26 'left_field' => 'tid',
Chris@0 27 ],
Chris@0 28 ];
Chris@0 29
Chris@0 30 $data['taxonomy_term_field_data']['tid']['help'] = $this->t('The tid of a taxonomy term.');
Chris@0 31
Chris@0 32 $data['taxonomy_term_field_data']['tid']['argument']['id'] = 'taxonomy';
Chris@0 33 $data['taxonomy_term_field_data']['tid']['argument']['name field'] = 'name';
Chris@0 34 $data['taxonomy_term_field_data']['tid']['argument']['zero is null'] = TRUE;
Chris@0 35
Chris@0 36 $data['taxonomy_term_field_data']['tid']['filter']['id'] = 'taxonomy_index_tid';
Chris@0 37 $data['taxonomy_term_field_data']['tid']['filter']['title'] = $this->t('Term');
Chris@0 38 $data['taxonomy_term_field_data']['tid']['filter']['help'] = $this->t('Taxonomy term chosen from autocomplete or select widget.');
Chris@17 39 $data['taxonomy_term_field_data']['tid']['filter']['hierarchy table'] = 'taxonomy_term__parent';
Chris@0 40 $data['taxonomy_term_field_data']['tid']['filter']['numeric'] = TRUE;
Chris@0 41
Chris@0 42 $data['taxonomy_term_field_data']['tid_raw'] = [
Chris@0 43 'title' => $this->t('Term ID'),
Chris@0 44 'help' => $this->t('The tid of a taxonomy term.'),
Chris@0 45 'real field' => 'tid',
Chris@0 46 'filter' => [
Chris@0 47 'id' => 'numeric',
Chris@0 48 'allow empty' => TRUE,
Chris@0 49 ],
Chris@0 50 ];
Chris@0 51
Chris@0 52 $data['taxonomy_term_field_data']['tid_representative'] = [
Chris@0 53 'relationship' => [
Chris@0 54 'title' => $this->t('Representative node'),
Chris@0 55 'label' => $this->t('Representative node'),
Chris@0 56 'help' => $this->t('Obtains a single representative node for each term, according to a chosen sort criterion.'),
Chris@0 57 'id' => 'groupwise_max',
Chris@0 58 'relationship field' => 'tid',
Chris@0 59 'outer field' => 'taxonomy_term_field_data.tid',
Chris@0 60 'argument table' => 'taxonomy_term_field_data',
Chris@0 61 'argument field' => 'tid',
Chris@0 62 'base' => 'node_field_data',
Chris@0 63 'field' => 'nid',
Chris@17 64 'relationship' => 'node_field_data:term_node_tid',
Chris@0 65 ],
Chris@0 66 ];
Chris@0 67
Chris@0 68 $data['taxonomy_term_field_data']['vid']['help'] = $this->t('Filter the results of "Taxonomy: Term" to a particular vocabulary.');
Chris@17 69 $data['taxonomy_term_field_data']['vid']['field']['help'] = t('The vocabulary name.');
Chris@0 70 $data['taxonomy_term_field_data']['vid']['argument']['id'] = 'vocabulary_vid';
Chris@0 71 unset($data['taxonomy_term_field_data']['vid']['sort']);
Chris@0 72
Chris@0 73 $data['taxonomy_term_field_data']['name']['field']['id'] = 'term_name';
Chris@0 74 $data['taxonomy_term_field_data']['name']['argument']['many to one'] = TRUE;
Chris@0 75 $data['taxonomy_term_field_data']['name']['argument']['empty field name'] = $this->t('Uncategorized');
Chris@0 76
Chris@0 77 $data['taxonomy_term_field_data']['description__value']['field']['click sortable'] = FALSE;
Chris@0 78
Chris@0 79 $data['taxonomy_term_field_data']['changed']['title'] = $this->t('Updated date');
Chris@0 80 $data['taxonomy_term_field_data']['changed']['help'] = $this->t('The date the term was last updated.');
Chris@0 81
Chris@0 82 $data['taxonomy_term_field_data']['changed_fulldate'] = [
Chris@0 83 'title' => $this->t('Updated date'),
Chris@0 84 'help' => $this->t('Date in the form of CCYYMMDD.'),
Chris@0 85 'argument' => [
Chris@0 86 'field' => 'changed',
Chris@0 87 'id' => 'date_fulldate',
Chris@0 88 ],
Chris@0 89 ];
Chris@0 90
Chris@0 91 $data['taxonomy_term_field_data']['changed_year_month'] = [
Chris@0 92 'title' => $this->t('Updated year + month'),
Chris@0 93 'help' => $this->t('Date in the form of YYYYMM.'),
Chris@0 94 'argument' => [
Chris@0 95 'field' => 'changed',
Chris@0 96 'id' => 'date_year_month',
Chris@0 97 ],
Chris@0 98 ];
Chris@0 99
Chris@0 100 $data['taxonomy_term_field_data']['changed_year'] = [
Chris@0 101 'title' => $this->t('Updated year'),
Chris@0 102 'help' => $this->t('Date in the form of YYYY.'),
Chris@0 103 'argument' => [
Chris@0 104 'field' => 'changed',
Chris@0 105 'id' => 'date_year',
Chris@0 106 ],
Chris@0 107 ];
Chris@0 108
Chris@0 109 $data['taxonomy_term_field_data']['changed_month'] = [
Chris@0 110 'title' => $this->t('Updated month'),
Chris@0 111 'help' => $this->t('Date in the form of MM (01 - 12).'),
Chris@0 112 'argument' => [
Chris@0 113 'field' => 'changed',
Chris@0 114 'id' => 'date_month',
Chris@0 115 ],
Chris@0 116 ];
Chris@0 117
Chris@0 118 $data['taxonomy_term_field_data']['changed_day'] = [
Chris@0 119 'title' => $this->t('Updated day'),
Chris@0 120 'help' => $this->t('Date in the form of DD (01 - 31).'),
Chris@0 121 'argument' => [
Chris@0 122 'field' => 'changed',
Chris@0 123 'id' => 'date_day',
Chris@0 124 ],
Chris@0 125 ];
Chris@0 126
Chris@0 127 $data['taxonomy_term_field_data']['changed_week'] = [
Chris@0 128 'title' => $this->t('Updated week'),
Chris@0 129 'help' => $this->t('Date in the form of WW (01 - 53).'),
Chris@0 130 'argument' => [
Chris@0 131 'field' => 'changed',
Chris@0 132 'id' => 'date_week',
Chris@0 133 ],
Chris@0 134 ];
Chris@0 135
Chris@17 136 $data['taxonomy_index']['table']['group'] = $this->t('Taxonomy term');
Chris@0 137
Chris@0 138 $data['taxonomy_index']['table']['join'] = [
Chris@0 139 'taxonomy_term_field_data' => [
Chris@0 140 // links directly to taxonomy_term_field_data via tid
Chris@0 141 'left_field' => 'tid',
Chris@0 142 'field' => 'tid',
Chris@0 143 ],
Chris@0 144 'node_field_data' => [
Chris@0 145 // links directly to node via nid
Chris@0 146 'left_field' => 'nid',
Chris@0 147 'field' => 'nid',
Chris@0 148 ],
Chris@17 149 'taxonomy_term__parent' => [
Chris@17 150 'left_field' => 'entity_id',
Chris@0 151 'field' => 'tid',
Chris@0 152 ],
Chris@0 153 ];
Chris@0 154
Chris@0 155 $data['taxonomy_index']['nid'] = [
Chris@0 156 'title' => $this->t('Content with term'),
Chris@0 157 'help' => $this->t('Relate all content tagged with a term.'),
Chris@0 158 'relationship' => [
Chris@0 159 'id' => 'standard',
Chris@0 160 'base' => 'node',
Chris@0 161 'base field' => 'nid',
Chris@0 162 'label' => $this->t('node'),
Chris@0 163 'skip base' => 'node',
Chris@0 164 ],
Chris@0 165 ];
Chris@0 166
Chris@0 167 // @todo This stuff needs to move to a node field since really it's all
Chris@0 168 // about nodes.
Chris@0 169 $data['taxonomy_index']['tid'] = [
Chris@0 170 'group' => $this->t('Content'),
Chris@0 171 'title' => $this->t('Has taxonomy term ID'),
Chris@0 172 'help' => $this->t('Display content if it has the selected taxonomy terms.'),
Chris@0 173 'argument' => [
Chris@0 174 'id' => 'taxonomy_index_tid',
Chris@0 175 'name table' => 'taxonomy_term_field_data',
Chris@0 176 'name field' => 'name',
Chris@0 177 'empty field name' => $this->t('Uncategorized'),
Chris@0 178 'numeric' => TRUE,
Chris@0 179 'skip base' => 'taxonomy_term_field_data',
Chris@0 180 ],
Chris@0 181 'filter' => [
Chris@0 182 'title' => $this->t('Has taxonomy term'),
Chris@0 183 'id' => 'taxonomy_index_tid',
Chris@17 184 'hierarchy table' => 'taxonomy_term__parent',
Chris@0 185 'numeric' => TRUE,
Chris@0 186 'skip base' => 'taxonomy_term_field_data',
Chris@0 187 'allow empty' => TRUE,
Chris@0 188 ],
Chris@0 189 ];
Chris@0 190
Chris@0 191 $data['taxonomy_index']['status'] = [
Chris@0 192 'title' => $this->t('Publish status'),
Chris@0 193 'help' => $this->t('Whether or not the content related to a term is published.'),
Chris@0 194 'filter' => [
Chris@0 195 'id' => 'boolean',
Chris@0 196 'label' => $this->t('Published status'),
Chris@0 197 'type' => 'yes-no',
Chris@0 198 ],
Chris@0 199 ];
Chris@0 200
Chris@0 201 $data['taxonomy_index']['sticky'] = [
Chris@0 202 'title' => $this->t('Sticky status'),
Chris@0 203 'help' => $this->t('Whether or not the content related to a term is sticky.'),
Chris@0 204 'filter' => [
Chris@0 205 'id' => 'boolean',
Chris@0 206 'label' => $this->t('Sticky status'),
Chris@0 207 'type' => 'yes-no',
Chris@0 208 ],
Chris@0 209 'sort' => [
Chris@0 210 'id' => 'standard',
Chris@0 211 'help' => $this->t('Whether or not the content related to a term is sticky. To list sticky content first, set this to descending.'),
Chris@0 212 ],
Chris@0 213 ];
Chris@0 214
Chris@0 215 $data['taxonomy_index']['created'] = [
Chris@0 216 'title' => $this->t('Post date'),
Chris@0 217 'help' => $this->t('The date the content related to a term was posted.'),
Chris@0 218 'sort' => [
Chris@17 219 'id' => 'date',
Chris@0 220 ],
Chris@0 221 'filter' => [
Chris@0 222 'id' => 'date',
Chris@0 223 ],
Chris@0 224 ];
Chris@0 225
Chris@17 226 // Link to self through left.parent = right.tid (going down in depth).
Chris@17 227 $data['taxonomy_term__parent']['table']['join']['taxonomy_term__parent'] = [
Chris@17 228 'left_field' => 'entity_id',
Chris@17 229 'field' => 'parent_target_id',
Chris@0 230 ];
Chris@0 231
Chris@17 232 $data['taxonomy_term__parent']['parent_target_id']['help'] = $this->t('The parent term of the term. This can produce duplicate entries if you are using a vocabulary that allows multiple parents.');
Chris@17 233 $data['taxonomy_term__parent']['parent_target_id']['relationship']['label'] = $this->t('Parent');
Chris@17 234 $data['taxonomy_term__parent']['parent_target_id']['argument']['id'] = 'taxonomy';
Chris@0 235
Chris@0 236 return $data;
Chris@0 237 }
Chris@0 238
Chris@0 239 }