Pathologic was missing because of a .git folder inside.
[yaffs-website] / web / modules / contrib / entityqueue / entityqueue.views.inc
1 <?php
2
3 /**
4  * @file
5  * Provide views data for the Entityqueue module.
6  */
7
8 use Drupal\Core\Entity\Sql\SqlEntityStorageInterface;
9 use Drupal\entityqueue\Entity\EntityQueue;
10
11 /**
12  * Implements hook_views_data_alter().
13  */
14 function entityqueue_views_data_alter(array &$data) {
15   $entity_type_manager = \Drupal::entityTypeManager();
16   $entity_subqueue = $entity_type_manager->getDefinition('entity_subqueue');
17
18   // Find all entity types that need an 'entityqueue' relationship.
19   $target_entity_type_ids = [];
20   $queues = EntityQueue::loadMultiple();
21   foreach ($queues as $queue) {
22     $target_entity_type_ids[$queue->getTargetEntityTypeId()] = TRUE;
23   }
24
25   // Filter entity types to those that have a 'views_data' handler and use a SQL
26   // storage.
27   /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
28   $entity_types = [];
29   foreach (array_keys($target_entity_type_ids) as $entity_type_id) {
30     $entity_type = $entity_type_manager->getDefinition($entity_type_id);
31     if ($entity_type->hasHandlerClass('views_data') && $entity_type_manager->getStorage($entity_type->id()) instanceof SqlEntityStorageInterface) {
32       $entity_types[$entity_type_id] = $entity_type;
33     }
34   }
35
36   foreach ($entity_types as $entity_type_id => $entity_type) {
37     $field_name = 'items';
38     $field_storage = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions('entity_subqueue')[$field_name];
39     $target_base_table = $entity_type->getDataTable() ?: $entity_type->getBaseTable();
40
41     /** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
42     $table_mapping = $entity_type_manager->getStorage('entity_subqueue')->getTableMapping();
43     $columns = $table_mapping->getColumnNames($field_name);
44     $subqueue_items_table_name = $table_mapping->getDedicatedDataTableName($field_storage);
45
46     $data[$target_base_table]['entityqueue_relationship']['relationship'] = [
47       'id' => 'entity_queue',
48       'title' => t('@target_label queue', ['@target_label' => $entity_type->getLabel()]),
49       'label' => t('@target_label queue', ['@target_label' => $entity_type->getLabel()]),
50       'group' => t('Entityqueue'),
51       'help' => t('Create a relationship from @target_label to an entityqueue.', ['@target_label' => $entity_type->getLabel()]),
52       'base' => $entity_subqueue->getDataTable() ?: $entity_subqueue->getBaseTable(),
53       'entity_type' => 'entity_subqueue',
54       'base field' => $entity_subqueue->getKey('id'),
55       'field_name' => $field_storage->getName(),
56       'field table' => $subqueue_items_table_name,
57       'field field' => $columns['target_id'],
58     ];
59
60     $data[$target_base_table]['entityqueue_relationship']['sort'] = array(
61       'id' => 'entity_queue_position',
62       'group' => t('Entityqueue'),
63       'title' => t('@target_label Queue Position', array(
64         '@target_label' => $entity_type->getLabel(),
65       )),
66       'label' => t('@target_label Queue Position', array(
67         '@target_label' => $entity_type->getLabel(),
68       )),
69       'help' => t('Position of item in the @target_label queue.', array(
70         '@target_label' => $entity_type->getLabel(),
71       )),
72       'field' => 'delta',
73       'field table' => $subqueue_items_table_name,
74       'field_name' => $field_name,
75     );
76
77     $data[$target_base_table]['entityqueue_relationship']['filter'] = array(
78       'id' => 'entity_queue_in_queue',
79       'type' => 'yes-no',
80       'group' => t('Entityqueue'),
81       'title' => t('@target_label In Queue', array(
82         '@target_label' => $entity_type->getLabel(),
83       )),
84       'label' => t('@target_label In Queue', array(
85         '@target_label' => $entity_type->getLabel(),
86       )),
87       'help' => t('Filter for entities that are available or not in the @target_label entity queue.', array(
88         '@target_label' => $entity_type->getLabel(),
89       )),
90       'field table' => $subqueue_items_table_name,
91       'field field' => $columns['target_id'],
92     );
93   }
94 }