taxonomy.views.inc 3.0 KB

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