TermViewsData.php 9.39 KB
Newer Older
1 2 3 4 5 6 7 8 9
<?php

/**
 * @file
 * Contains \Drupal\taxonomy\TermViewsData.
 */

namespace Drupal\taxonomy;

10
use Drupal\views\EntityViewsData;
11 12 13 14

/**
 * Provides the views data for the taxonomy entity type.
 */
15
class TermViewsData extends EntityViewsData {
16 17 18 19 20

  /**
   * {@inheritdoc}
   */
  public function getViewsData() {
21 22
    $data = parent::getViewsData();

23 24 25
    $data['taxonomy_term_field_data']['table']['base']['help'] = t('Taxonomy terms are attached to nodes.');
    $data['taxonomy_term_field_data']['table']['base']['access query tag'] = 'term_access';
    $data['taxonomy_term_field_data']['table']['wizard_id'] = 'taxonomy_term';
26

27
    $data['taxonomy_term_field_data']['table']['join'] = array(
28 29 30 31 32 33 34
      // This is provided for the many_to_one argument.
      'taxonomy_index' => array(
        'field' => 'tid',
        'left_field' => 'tid',
      ),
    );

35
    $data['taxonomy_term_field_data']['tid']['help'] = t('The tid of a taxonomy term.');
36

37 38 39
    $data['taxonomy_term_field_data']['tid']['argument']['id'] = 'taxonomy';
    $data['taxonomy_term_field_data']['tid']['argument']['name field'] = 'name';
    $data['taxonomy_term_field_data']['tid']['argument']['zero is null'] = TRUE;
40

41 42 43 44 45
    $data['taxonomy_term_field_data']['tid']['filter']['id'] = 'taxonomy_index_tid';
    $data['taxonomy_term_field_data']['tid']['filter']['title'] = t('Term');
    $data['taxonomy_term_field_data']['tid']['filter']['help'] = t('Taxonomy term chosen from autocomplete or select widget.');
    $data['taxonomy_term_field_data']['tid']['filter']['hierarchy table'] = 'taxonomy_term_hierarchy';
    $data['taxonomy_term_field_data']['tid']['filter']['numeric'] = TRUE;
46

47
    $data['taxonomy_term_field_data']['tid_raw'] = array(
48 49 50 51 52 53 54 55 56
      'title' => t('Term ID'),
      'help' => t('The tid of a taxonomy term.'),
      'real field' => 'tid',
      'filter' => array(
        'id' => 'numeric',
        'allow empty' => TRUE,
      ),
    );

57
    $data['taxonomy_term_field_data']['tid_representative'] = array(
58 59 60 61 62 63
      'relationship' => array(
        'title' => t('Representative node'),
        'label'  => t('Representative node'),
        'help' => t('Obtains a single representative node for each term, according to a chosen sort criterion.'),
        'id' => 'groupwise_max',
        'relationship field' => 'tid',
64
        'outer field' => 'taxonomy_term_field_data.tid',
65 66
        'argument table' => 'taxonomy_term_field_data',
        'argument field' =>  'tid',
67
        'base'   => 'node_field_data',
68
        'field'  => 'nid',
69
        'relationship' => 'node_field_data:term_node_tid'
70 71 72
      ),
    );

73 74 75 76
    $data['taxonomy_term_field_data']['vid']['help'] = t('Filter the results of "Taxonomy: Term" to a particular vocabulary.');
    unset($data['taxonomy_term_field_data']['vid']['field']);
    unset($data['taxonomy_term_field_data']['vid']['argument']);
    unset($data['taxonomy_term_field_data']['vid']['sort']);
77 78 79 80 81 82 83 84 85 86

    $data['taxonomy_term_data']['edit_term'] = array(
      'field' => array(
        'title' => t('Term edit link'),
        'help' => t('Provide a simple link to edit the term.'),
        'id' => 'term_link_edit',
        'click sortable' => FALSE,
      ),
    );

87 88 89 90 91 92 93 94 95 96
    if (\Drupal::moduleHandler()->moduleExists('content_translation')) {
      $data['taxonomy_term_data']['translation_link'] = array(
        'title' => t('Translation link'),
        'help' => t('Provide a link to the translations overview for taxonomy terms.'),
        'field' => array(
          'id' => 'content_translation_link',
        ),
      );
    }

97
    $data['taxonomy_term_field_data']['name']['field']['id'] = 'term_name';
98 99 100 101 102 103 104
    $data['taxonomy_term_field_data']['name']['argument']['many to one'] = TRUE;
    $data['taxonomy_term_field_data']['name']['argument']['empty field name'] = t('Uncategorized');

    $data['taxonomy_term_field_data']['description__value']['field']['click sortable'] = FALSE;

    $data['taxonomy_term_field_data']['changed']['title'] = t('Updated date');
    $data['taxonomy_term_field_data']['changed']['help'] = t('The date the term was last updated.');
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167

    $data['taxonomy_term_field_data']['changed_fulldate'] = array(
      'title' => t('Updated date'),
      'help' => t('Date in the form of CCYYMMDD.'),
      'argument' => array(
        'field' => 'changed',
        'id' => 'date_fulldate',
      ),
    );

    $data['taxonomy_term_field_data']['changed_year_month'] = array(
      'title' => t('Updated year + month'),
      'help' => t('Date in the form of YYYYMM.'),
      'argument' => array(
        'field' => 'changed',
        'id' => 'date_year_month',
      ),
    );

    $data['taxonomy_term_field_data']['changed_year'] = array(
      'title' => t('Updated year'),
      'help' => t('Date in the form of YYYY.'),
      'argument' => array(
        'field' => 'changed',
        'id' => 'date_year',
      ),
    );

    $data['taxonomy_term_field_data']['changed_month'] = array(
      'title' => t('Updated month'),
      'help' => t('Date in the form of MM (01 - 12).'),
      'argument' => array(
        'field' => 'changed',
        'id' => 'date_month',
      ),
    );

    $data['taxonomy_term_field_data']['changed_day'] = array(
      'title' => t('Updated day'),
      'help' => t('Date in the form of DD (01 - 31).'),
      'argument' => array(
        'field' => 'changed',
        'id' => 'date_day',
      ),
    );

    $data['taxonomy_term_field_data']['changed_week'] = array(
      'title' => t('Updated week'),
      'help' => t('Date in the form of WW (01 - 53).'),
      'argument' => array(
        'field' => 'changed',
        'id' => 'date_week',
      ),
    );

    $data['taxonomy_index']['table']['group']  = t('Taxonomy term');

    $data['taxonomy_index']['table']['join'] = array(
      'taxonomy_term_data' => array(
        // links directly to taxonomy_term_data via tid
        'left_field' => 'tid',
        'field' => 'tid',
      ),
168
      'node_field_data' => array(
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
        // links directly to node via nid
        'left_field' => 'nid',
        'field' => 'nid',
      ),
      'taxonomy_term_hierarchy' => array(
        'left_field' => 'tid',
        'field' => 'tid',
      ),
    );

    $data['taxonomy_index']['nid'] = array(
      'title' => t('Content with term'),
      'help' => t('Relate all content tagged with a term.'),
      'relationship' => array(
        'id' => 'standard',
        'base' => 'node',
        'base field' => 'nid',
        'label' => t('node'),
        'skip base' => 'node',
      ),
    );

    // @todo This stuff needs to move to a node field since really it's all about
    //   nodes.
    $data['taxonomy_index']['tid'] = array(
      'group' => t('Content'),
      'title' => t('Has taxonomy term ID'),
      'help' => t('Display content if it has the selected taxonomy terms.'),
      'argument' => array(
        'id' => 'taxonomy_index_tid',
        'name table' => 'taxonomy_term_field_data',
        'name field' => 'name',
        'empty field name' => t('Uncategorized'),
        'numeric' => TRUE,
203
        'skip base' => 'taxonomy_term_field_data',
204 205 206 207 208 209
      ),
      'filter' => array(
        'title' => t('Has taxonomy term'),
        'id' => 'taxonomy_index_tid',
        'hierarchy table' => 'taxonomy_term_hierarchy',
        'numeric' => TRUE,
210
        'skip base' => 'taxonomy_term_field_data',
211 212 213 214
        'allow empty' => TRUE,
      ),
    );

215 216 217 218 219 220 221 222 223
    $data['taxonomy_index']['status'] = [
      'title' => t('Publish status'),
      'help' => t('Whether or not the content related to a term is published.'),
      'filter' => [
        'id' => 'boolean',
        'label' => t('Published status'),
        'type' => 'yes-no',
      ],
    ];
224

225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
    $data['taxonomy_index']['sticky'] = [
      'title' => t('Sticky status'),
      'help' => t('Whether or not the content related to a term is sticky.'),
      'filter' => [
        'id' => 'boolean',
        'label' => t('Sticky status'),
        'type' => 'yes-no',
      ],
      'sort' => [
        'id' => 'standard',
        'help' => t('Whether or not the content related to a term is sticky. To list sticky content first, set this to descending.'),
      ],
    ];

    $data['taxonomy_index']['created'] = [
      'title' => t('Post date'),
      'help' => t('The date the content related to a term was posted.'),
      'sort' => [
        'id' => 'date'
      ],
      'filter' => [
        'id' => 'date',
      ],
    ];
249

250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
    $data['taxonomy_term_hierarchy']['table']['group']  = t('Taxonomy term');

    $data['taxonomy_term_hierarchy']['table']['join'] = array(
      'taxonomy_term_hierarchy' => array(
        // Link to self through left.parent = right.tid (going down in depth).
        'left_field' => 'tid',
        'field' => 'parent',
      ),
      'taxonomy_term_data' => array(
        // Link directly to taxonomy_term_data via tid.
        'left_field' => 'tid',
        'field' => 'tid',
      ),
    );

    $data['taxonomy_term_hierarchy']['parent'] = array(
      'title' => t('Parent term'),
      'help' => t('The parent term of the term. This can produce duplicate entries if you are using a vocabulary that allows multiple parents.'),
      'relationship' => array(
        'base' => 'taxonomy_term_data',
        'field' => 'parent',
        'label' => t('Parent'),
        'id' => 'standard',
      ),
      'filter' => array(
        'help' => t('Filter the results of "Taxonomy: Term" by the parent pid.'),
        'id' => 'numeric',
      ),
      'argument' => array(
        'help' => t('The parent term of the term.'),
        'id' => 'taxonomy',
      ),
    );

    return $data;
  }

}