-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpcx_connect.views.inc
199 lines (181 loc) · 5.19 KB
/
pcx_connect.views.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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
168
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
<?php
/**
* @file
* Views hook implementations for the PCX Connect module.
*/
use Drupal\pcx_connect\Entity\PccSite;
use Drupal\pcx_connect\PccSiteViewHelper;
/**
* Implements hook_views_data().
*/
function pcx_connect_views_data() {
$data = [];
$pcc_sites = PccSite::loadMultiple();
if ($pcc_sites) {
$translation = \Drupal::translation();
foreach ($pcc_sites as $pcc_site) {
$id = $pcc_site->getEntityTypeId();
$name = $pcc_site->label();
$table = &$data[$pcc_site->id()];
// Base data.
$table['table']['group'] = $translation->translate('PCC Site - @name', ['@name' => $name]);
$table['table']['provider'] = $id;
// Locate the config entity type's ID.
$entityType = \Drupal::entityTypeManager()
->getStorage($id)
->getEntityType();
$id_key = $entityType->getKey('id');
// Get entity fields.
$fields = PccSiteViewHelper::getMapping($id);
if (empty($fields[$id_key])) {
continue;
}
if (empty($fields[$id_key]['label'])) {
continue;
}
$table['table']['base'] = [
'field' => strtolower($fields[$id_key]['label']),
'index' => strtolower($fields[$id_key]['label']),
'title' => $translation->translate('PCC Site - @name', ['@name' => $name]),
'help' => $translation->translate('Use the ConfigEntity @name to view the data.', ['@name' => $name]),
'query_id' => 'pcc_site_view_query',
];
$table['id'] = [
'title' => $translation->translate('ID'),
'help' => $translation->translate('PCC Doc ID'),
'field' => [
'id' => 'standard',
'click sortable' => TRUE,
],
'sort' => [
'id' => 'standard',
],
'filter' => [
'id' => 'string',
],
'argument' => [
'id' => 'string',
],
];
$table['title'] = [
'title' => $translation->translate('Title'),
'help' => $translation->translate('PCC Doc title'),
'field' => [
'id' => 'standard',
'click sortable' => TRUE,
],
'sort' => [
'id' => 'standard',
],
'filter' => [
'id' => 'string',
],
'argument' => [
'id' => 'string',
],
];
$table['content'] = [
'title' => $translation->translate('Content'),
'help' => $translation->translate('PCC Doc Content'),
'field' => [
'id' => 'pcc_content',
'click sortable' => FALSE,
],
'filter' => [
'id' => 'string',
],
'argument' => [
'id' => 'string',
],
];
$table['snippet'] = [
'title' => $translation->translate('Snippet'),
'help' => $translation->translate('PCC Doc Snippet'),
'field' => [
'id' => 'pcc_content',
'click sortable' => FALSE,
],
];
$table['publishedDate'] = [
'title' => $translation->translate('Published Date'),
'help' => $translation->translate('PCC Doc publish time'),
'field' => [
'id' => 'date',
'click sortable' => TRUE,
],
'sort' => [
'id' => 'date',
],
];
$table['updatedAt'] = [
'title' => $translation->translate('Updated At'),
'help' => $translation->translate('PCC Doc update time'),
'field' => [
'id' => 'date',
'click sortable' => TRUE,
],
'sort' => [
'id' => 'date',
],
];
$table['previewActiveUntil'] = [
'title' => $translation->translate('Preview Active Until'),
'help' => $translation->translate('PCC Doc Preview Active Until'),
'field' => [
'id' => 'standard',
'click sortable' => TRUE,
],
];
$table['slug'] = [
'title' => $translation->translate('Slug'),
'help' => $translation->translate('PCC Doc Slug'),
'field' => [
'id' => 'standard',
'click sortable' => FALSE,
],
'filter' => [
'id' => 'string',
],
'argument' => [
'id' => 'string',
],
];
$table['tags'] = [
'title' => $translation->translate('Tags'),
'help' => $translation->translate('PCC Doc tags'),
'field' => [
'id' => 'pcc_tags',
'click sortable' => FALSE,
],
'filter' => [
'id' => 'string',
],
'argument' => [
'id' => 'string',
],
];
$table['publishingLevel'] = [
'title' => $translation->translate('Publishing level'),
'help' => $translation->translate('PCC Doc Publishing level'),
'field' => [
'id' => 'standard',
'click sortable' => TRUE,
],
'filter' => [
'id' => 'string',
],
'argument' => [
'id' => 'string',
],
];
$table['metadata'] = [
'title' => $translation->translate('Metadata'),
'help' => $translation->translate('PCC Doc Metadata'),
'field' => [
'id' => 'pcc_metadata',
],
];
}
}
return array_filter($data);
}