TermViewsData.php 9.0 KB

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