Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\content_moderation;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Core\Entity\EntityTypeInterface;
|
Chris@0
|
6 use Drupal\Core\Entity\EntityTypeManagerInterface;
|
Chris@0
|
7 use Drupal\Core\StringTranslation\StringTranslationTrait;
|
Chris@0
|
8
|
Chris@0
|
9 /**
|
Chris@0
|
10 * Provides the content_moderation views integration.
|
Chris@0
|
11 *
|
Chris@0
|
12 * @internal
|
Chris@0
|
13 */
|
Chris@0
|
14 class ViewsData {
|
Chris@0
|
15
|
Chris@0
|
16 use StringTranslationTrait;
|
Chris@0
|
17
|
Chris@0
|
18 /**
|
Chris@0
|
19 * The entity type manager.
|
Chris@0
|
20 *
|
Chris@0
|
21 * @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
Chris@0
|
22 */
|
Chris@0
|
23 protected $entityTypeManager;
|
Chris@0
|
24
|
Chris@0
|
25 /**
|
Chris@0
|
26 * The moderation information.
|
Chris@0
|
27 *
|
Chris@0
|
28 * @var \Drupal\content_moderation\ModerationInformationInterface
|
Chris@0
|
29 */
|
Chris@0
|
30 protected $moderationInformation;
|
Chris@0
|
31
|
Chris@0
|
32 /**
|
Chris@0
|
33 * Creates a new ViewsData instance.
|
Chris@0
|
34 *
|
Chris@0
|
35 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
Chris@0
|
36 * The entity type manager.
|
Chris@0
|
37 * @param \Drupal\content_moderation\ModerationInformationInterface $moderation_information
|
Chris@0
|
38 * The moderation information.
|
Chris@0
|
39 */
|
Chris@0
|
40 public function __construct(EntityTypeManagerInterface $entity_type_manager, ModerationInformationInterface $moderation_information) {
|
Chris@0
|
41 $this->entityTypeManager = $entity_type_manager;
|
Chris@0
|
42 $this->moderationInformation = $moderation_information;
|
Chris@0
|
43 }
|
Chris@0
|
44
|
Chris@0
|
45 /**
|
Chris@0
|
46 * Returns the views data.
|
Chris@0
|
47 *
|
Chris@0
|
48 * @return array
|
Chris@0
|
49 * The views data.
|
Chris@0
|
50 */
|
Chris@0
|
51 public function getViewsData() {
|
Chris@0
|
52 $data = [];
|
Chris@0
|
53
|
Chris@0
|
54 $entity_types_with_moderation = array_filter($this->entityTypeManager->getDefinitions(), function (EntityTypeInterface $type) {
|
Chris@18
|
55 return $this->moderationInformation->isModeratedEntityType($type);
|
Chris@0
|
56 });
|
Chris@0
|
57
|
Chris@0
|
58 // Provides a relationship from moderated entity to its moderation state
|
Chris@0
|
59 // entity.
|
Chris@0
|
60 $content_moderation_state_entity_type = $this->entityTypeManager->getDefinition('content_moderation_state');
|
Chris@0
|
61 $content_moderation_state_entity_base_table = $content_moderation_state_entity_type->getDataTable() ?: $content_moderation_state_entity_type->getBaseTable();
|
Chris@0
|
62 $content_moderation_state_entity_revision_base_table = $content_moderation_state_entity_type->getRevisionDataTable() ?: $content_moderation_state_entity_type->getRevisionTable();
|
Chris@0
|
63 foreach ($entity_types_with_moderation as $entity_type_id => $entity_type) {
|
Chris@0
|
64 $table = $entity_type->getDataTable() ?: $entity_type->getBaseTable();
|
Chris@0
|
65
|
Chris@0
|
66 $data[$table]['moderation_state'] = [
|
Chris@0
|
67 'title' => t('Moderation state'),
|
Chris@0
|
68 'relationship' => [
|
Chris@0
|
69 'id' => 'standard',
|
Chris@0
|
70 'label' => $this->t('@label moderation state', ['@label' => $entity_type->getLabel()]),
|
Chris@0
|
71 'base' => $content_moderation_state_entity_base_table,
|
Chris@0
|
72 'base field' => 'content_entity_id',
|
Chris@0
|
73 'relationship field' => $entity_type->getKey('id'),
|
Chris@0
|
74 'extra' => [
|
Chris@0
|
75 [
|
Chris@0
|
76 'field' => 'content_entity_type_id',
|
Chris@0
|
77 'value' => $entity_type_id,
|
Chris@0
|
78 ],
|
Chris@0
|
79 ],
|
Chris@0
|
80 ],
|
Chris@14
|
81 'field' => [
|
Chris@14
|
82 'id' => 'field',
|
Chris@14
|
83 'default_formatter' => 'content_moderation_state',
|
Chris@14
|
84 'field_name' => 'moderation_state',
|
Chris@14
|
85 ],
|
Chris@14
|
86 'filter' => ['id' => 'moderation_state_filter', 'allow empty' => TRUE],
|
Chris@0
|
87 ];
|
Chris@0
|
88
|
Chris@0
|
89 $revision_table = $entity_type->getRevisionDataTable() ?: $entity_type->getRevisionTable();
|
Chris@0
|
90 $data[$revision_table]['moderation_state'] = [
|
Chris@0
|
91 'title' => t('Moderation state'),
|
Chris@0
|
92 'relationship' => [
|
Chris@0
|
93 'id' => 'standard',
|
Chris@0
|
94 'label' => $this->t('@label moderation state', ['@label' => $entity_type->getLabel()]),
|
Chris@0
|
95 'base' => $content_moderation_state_entity_revision_base_table,
|
Chris@0
|
96 'base field' => 'content_entity_revision_id',
|
Chris@0
|
97 'relationship field' => $entity_type->getKey('revision'),
|
Chris@0
|
98 'extra' => [
|
Chris@0
|
99 [
|
Chris@0
|
100 'field' => 'content_entity_type_id',
|
Chris@0
|
101 'value' => $entity_type_id,
|
Chris@0
|
102 ],
|
Chris@0
|
103 ],
|
Chris@0
|
104 ],
|
Chris@14
|
105 'field' => [
|
Chris@14
|
106 'id' => 'field',
|
Chris@14
|
107 'default_formatter' => 'content_moderation_state',
|
Chris@14
|
108 'field_name' => 'moderation_state',
|
Chris@14
|
109 ],
|
Chris@14
|
110 'filter' => ['id' => 'moderation_state_filter', 'allow empty' => TRUE],
|
Chris@0
|
111 ];
|
Chris@0
|
112 }
|
Chris@0
|
113
|
Chris@0
|
114 return $data;
|
Chris@0
|
115 }
|
Chris@0
|
116
|
Chris@0
|
117 }
|