Mercurial > hg > isophonics-drupal-site
comparison core/modules/comment/src/CommentViewsData.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\comment; | |
4 | |
5 use Drupal\Core\Entity\ContentEntityInterface; | |
6 use Drupal\views\EntityViewsData; | |
7 | |
8 /** | |
9 * Provides views data for the comment entity type. | |
10 */ | |
11 class CommentViewsData extends EntityViewsData { | |
12 | |
13 /** | |
14 * {@inheritdoc} | |
15 */ | |
16 public function getViewsData() { | |
17 $data = parent::getViewsData(); | |
18 | |
19 $data['comment_field_data']['table']['base']['help'] = $this->t('Comments are responses to content.'); | |
20 $data['comment_field_data']['table']['base']['access query tag'] = 'comment_access'; | |
21 | |
22 $data['comment_field_data']['table']['wizard_id'] = 'comment'; | |
23 | |
24 $data['comment_field_data']['subject']['title'] = $this->t('Title'); | |
25 $data['comment_field_data']['subject']['help'] = $this->t('The title of the comment.'); | |
26 $data['comment_field_data']['subject']['field']['default_formatter'] = 'comment_permalink'; | |
27 | |
28 $data['comment_field_data']['name']['title'] = $this->t('Author'); | |
29 $data['comment_field_data']['name']['help'] = $this->t("The name of the comment's author. Can be rendered as a link to the author's homepage."); | |
30 $data['comment_field_data']['name']['field']['default_formatter'] = 'comment_username'; | |
31 | |
32 $data['comment_field_data']['homepage']['title'] = $this->t("Author's website"); | |
33 $data['comment_field_data']['homepage']['help'] = $this->t("The website address of the comment's author. Can be rendered as a link. Will be empty if the author is a registered user."); | |
34 | |
35 $data['comment_field_data']['mail']['help'] = $this->t('Email of user that posted the comment. Will be empty if the author is a registered user.'); | |
36 | |
37 $data['comment_field_data']['created']['title'] = $this->t('Post date'); | |
38 $data['comment_field_data']['created']['help'] = $this->t('Date and time of when the comment was created.'); | |
39 | |
40 $data['comment_field_data']['created_fulldata'] = [ | |
41 'title' => $this->t('Created date'), | |
42 'help' => $this->t('Date in the form of CCYYMMDD.'), | |
43 'argument' => [ | |
44 'field' => 'created', | |
45 'id' => 'date_fulldate', | |
46 ], | |
47 ]; | |
48 | |
49 $data['comment_field_data']['created_year_month'] = [ | |
50 'title' => $this->t('Created year + month'), | |
51 'help' => $this->t('Date in the form of YYYYMM.'), | |
52 'argument' => [ | |
53 'field' => 'created', | |
54 'id' => 'date_year_month', | |
55 ], | |
56 ]; | |
57 | |
58 $data['comment_field_data']['created_year'] = [ | |
59 'title' => $this->t('Created year'), | |
60 'help' => $this->t('Date in the form of YYYY.'), | |
61 'argument' => [ | |
62 'field' => 'created', | |
63 'id' => 'date_year', | |
64 ], | |
65 ]; | |
66 | |
67 $data['comment_field_data']['created_month'] = [ | |
68 'title' => $this->t('Created month'), | |
69 'help' => $this->t('Date in the form of MM (01 - 12).'), | |
70 'argument' => [ | |
71 'field' => 'created', | |
72 'id' => 'date_month', | |
73 ], | |
74 ]; | |
75 | |
76 $data['comment_field_data']['created_day'] = [ | |
77 'title' => $this->t('Created day'), | |
78 'help' => $this->t('Date in the form of DD (01 - 31).'), | |
79 'argument' => [ | |
80 'field' => 'created', | |
81 'id' => 'date_day', | |
82 ], | |
83 ]; | |
84 | |
85 $data['comment_field_data']['created_week'] = [ | |
86 'title' => $this->t('Created week'), | |
87 'help' => $this->t('Date in the form of WW (01 - 53).'), | |
88 'argument' => [ | |
89 'field' => 'created', | |
90 'id' => 'date_week', | |
91 ], | |
92 ]; | |
93 | |
94 $data['comment_field_data']['changed']['title'] = $this->t('Updated date'); | |
95 $data['comment_field_data']['changed']['help'] = $this->t('Date and time of when the comment was last updated.'); | |
96 | |
97 $data['comment_field_data']['changed_fulldata'] = [ | |
98 'title' => $this->t('Changed date'), | |
99 'help' => $this->t('Date in the form of CCYYMMDD.'), | |
100 'argument' => [ | |
101 'field' => 'changed', | |
102 'id' => 'date_fulldate', | |
103 ], | |
104 ]; | |
105 | |
106 $data['comment_field_data']['changed_year_month'] = [ | |
107 'title' => $this->t('Changed year + month'), | |
108 'help' => $this->t('Date in the form of YYYYMM.'), | |
109 'argument' => [ | |
110 'field' => 'changed', | |
111 'id' => 'date_year_month', | |
112 ], | |
113 ]; | |
114 | |
115 $data['comment_field_data']['changed_year'] = [ | |
116 'title' => $this->t('Changed year'), | |
117 'help' => $this->t('Date in the form of YYYY.'), | |
118 'argument' => [ | |
119 'field' => 'changed', | |
120 'id' => 'date_year', | |
121 ], | |
122 ]; | |
123 | |
124 $data['comment_field_data']['changed_month'] = [ | |
125 'title' => $this->t('Changed month'), | |
126 'help' => $this->t('Date in the form of MM (01 - 12).'), | |
127 'argument' => [ | |
128 'field' => 'changed', | |
129 'id' => 'date_month', | |
130 ], | |
131 ]; | |
132 | |
133 $data['comment_field_data']['changed_day'] = [ | |
134 'title' => $this->t('Changed day'), | |
135 'help' => $this->t('Date in the form of DD (01 - 31).'), | |
136 'argument' => [ | |
137 'field' => 'changed', | |
138 'id' => 'date_day', | |
139 ], | |
140 ]; | |
141 | |
142 $data['comment_field_data']['changed_week'] = [ | |
143 'title' => $this->t('Changed week'), | |
144 'help' => $this->t('Date in the form of WW (01 - 53).'), | |
145 'argument' => [ | |
146 'field' => 'changed', | |
147 'id' => 'date_week', | |
148 ], | |
149 ]; | |
150 | |
151 $data['comment_field_data']['status']['title'] = $this->t('Approved status'); | |
152 $data['comment_field_data']['status']['help'] = $this->t('Whether the comment is approved (or still in the moderation queue).'); | |
153 $data['comment_field_data']['status']['filter']['label'] = $this->t('Approved comment status'); | |
154 $data['comment_field_data']['status']['filter']['type'] = 'yes-no'; | |
155 | |
156 $data['comment']['approve_comment'] = [ | |
157 'field' => [ | |
158 'title' => $this->t('Link to approve comment'), | |
159 'help' => $this->t('Provide a simple link to approve the comment.'), | |
160 'id' => 'comment_link_approve', | |
161 ], | |
162 ]; | |
163 | |
164 $data['comment']['replyto_comment'] = [ | |
165 'field' => [ | |
166 'title' => $this->t('Link to reply-to comment'), | |
167 'help' => $this->t('Provide a simple link to reply to the comment.'), | |
168 'id' => 'comment_link_reply', | |
169 ], | |
170 ]; | |
171 | |
172 $data['comment_field_data']['entity_id']['field']['id'] = 'commented_entity'; | |
173 unset($data['comment_field_data']['entity_id']['relationship']); | |
174 | |
175 $data['comment']['comment_bulk_form'] = [ | |
176 'title' => $this->t('Comment operations bulk form'), | |
177 'help' => $this->t('Add a form element that lets you run operations on multiple comments.'), | |
178 'field' => [ | |
179 'id' => 'comment_bulk_form', | |
180 ], | |
181 ]; | |
182 | |
183 $data['comment_field_data']['thread']['field'] = [ | |
184 'title' => $this->t('Depth'), | |
185 'help' => $this->t('Display the depth of the comment if it is threaded.'), | |
186 'id' => 'comment_depth', | |
187 ]; | |
188 $data['comment_field_data']['thread']['sort'] = [ | |
189 'title' => $this->t('Thread'), | |
190 'help' => $this->t('Sort by the threaded order. This will keep child comments together with their parents.'), | |
191 'id' => 'comment_thread', | |
192 ]; | |
193 unset($data['comment_field_data']['thread']['filter']); | |
194 unset($data['comment_field_data']['thread']['argument']); | |
195 | |
196 $entities_types = \Drupal::entityManager()->getDefinitions(); | |
197 | |
198 // Provide a relationship for each entity type except comment. | |
199 foreach ($entities_types as $type => $entity_type) { | |
200 if ($type == 'comment' || !$entity_type->entityClassImplements(ContentEntityInterface::class) || !$entity_type->getBaseTable()) { | |
201 continue; | |
202 } | |
203 if ($fields = \Drupal::service('comment.manager')->getFields($type)) { | |
204 $data['comment_field_data'][$type] = [ | |
205 'relationship' => [ | |
206 'title' => $entity_type->getLabel(), | |
207 'help' => $this->t('The @entity_type to which the comment is a reply to.', ['@entity_type' => $entity_type->getLabel()]), | |
208 'base' => $entity_type->getDataTable() ?: $entity_type->getBaseTable(), | |
209 'base field' => $entity_type->getKey('id'), | |
210 'relationship field' => 'entity_id', | |
211 'id' => 'standard', | |
212 'label' => $entity_type->getLabel(), | |
213 'extra' => [ | |
214 [ | |
215 'field' => 'entity_type', | |
216 'value' => $type, | |
217 'table' => 'comment_field_data' | |
218 ], | |
219 ], | |
220 ], | |
221 ]; | |
222 } | |
223 } | |
224 | |
225 $data['comment_field_data']['uid']['title'] = $this->t('Author uid'); | |
226 $data['comment_field_data']['uid']['help'] = $this->t('If you need more fields than the uid add the comment: author relationship'); | |
227 $data['comment_field_data']['uid']['relationship']['title'] = $this->t('Author'); | |
228 $data['comment_field_data']['uid']['relationship']['help'] = $this->t("The User ID of the comment's author."); | |
229 $data['comment_field_data']['uid']['relationship']['label'] = $this->t('author'); | |
230 | |
231 $data['comment_field_data']['pid']['title'] = $this->t('Parent CID'); | |
232 $data['comment_field_data']['pid']['relationship']['title'] = $this->t('Parent comment'); | |
233 $data['comment_field_data']['pid']['relationship']['help'] = $this->t('The parent comment'); | |
234 $data['comment_field_data']['pid']['relationship']['label'] = $this->t('parent'); | |
235 | |
236 // Define the base group of this table. Fields that don't have a group defined | |
237 // will go into this field by default. | |
238 $data['comment_entity_statistics']['table']['group'] = $this->t('Comment Statistics'); | |
239 | |
240 // Provide a relationship for each entity type except comment. | |
241 foreach ($entities_types as $type => $entity_type) { | |
242 if ($type == 'comment' || !$entity_type->entityClassImplements(ContentEntityInterface::class) || !$entity_type->getBaseTable()) { | |
243 continue; | |
244 } | |
245 // This relationship does not use the 'field id' column, if the entity has | |
246 // multiple comment-fields, then this might introduce duplicates, in which | |
247 // case the site-builder should enable aggregation and SUM the comment_count | |
248 // field. We cannot create a relationship from the base table to | |
249 // {comment_entity_statistics} for each field as multiple joins between | |
250 // the same two tables is not supported. | |
251 if (\Drupal::service('comment.manager')->getFields($type)) { | |
252 $data['comment_entity_statistics']['table']['join'][$entity_type->getDataTable() ?: $entity_type->getBaseTable()] = [ | |
253 'type' => 'INNER', | |
254 'left_field' => $entity_type->getKey('id'), | |
255 'field' => 'entity_id', | |
256 'extra' => [ | |
257 [ | |
258 'field' => 'entity_type', | |
259 'value' => $type, | |
260 ], | |
261 ], | |
262 ]; | |
263 } | |
264 } | |
265 | |
266 $data['comment_entity_statistics']['last_comment_timestamp'] = [ | |
267 'title' => $this->t('Last comment time'), | |
268 'help' => $this->t('Date and time of when the last comment was posted.'), | |
269 'field' => [ | |
270 'id' => 'comment_last_timestamp', | |
271 ], | |
272 'sort' => [ | |
273 'id' => 'date', | |
274 ], | |
275 'filter' => [ | |
276 'id' => 'date', | |
277 ], | |
278 ]; | |
279 | |
280 $data['comment_entity_statistics']['last_comment_name'] = [ | |
281 'title' => $this->t("Last comment author"), | |
282 'help' => $this->t('The name of the author of the last posted comment.'), | |
283 'field' => [ | |
284 'id' => 'comment_ces_last_comment_name', | |
285 'no group by' => TRUE, | |
286 ], | |
287 'sort' => [ | |
288 'id' => 'comment_ces_last_comment_name', | |
289 'no group by' => TRUE, | |
290 ], | |
291 ]; | |
292 | |
293 $data['comment_entity_statistics']['comment_count'] = [ | |
294 'title' => $this->t('Comment count'), | |
295 'help' => $this->t('The number of comments an entity has.'), | |
296 'field' => [ | |
297 'id' => 'numeric', | |
298 ], | |
299 'filter' => [ | |
300 'id' => 'numeric', | |
301 ], | |
302 'sort' => [ | |
303 'id' => 'standard', | |
304 ], | |
305 'argument' => [ | |
306 'id' => 'standard', | |
307 ], | |
308 ]; | |
309 | |
310 $data['comment_entity_statistics']['last_updated'] = [ | |
311 'title' => $this->t('Updated/commented date'), | |
312 'help' => $this->t('The most recent of last comment posted or entity updated time.'), | |
313 'field' => [ | |
314 'id' => 'comment_ces_last_updated', | |
315 'no group by' => TRUE, | |
316 ], | |
317 'sort' => [ | |
318 'id' => 'comment_ces_last_updated', | |
319 'no group by' => TRUE, | |
320 ], | |
321 'filter' => [ | |
322 'id' => 'comment_ces_last_updated', | |
323 ], | |
324 ]; | |
325 | |
326 $data['comment_entity_statistics']['cid'] = [ | |
327 'title' => $this->t('Last comment CID'), | |
328 'help' => $this->t('Display the last comment of an entity'), | |
329 'relationship' => [ | |
330 'title' => $this->t('Last comment'), | |
331 'help' => $this->t('The last comment of an entity.'), | |
332 'group' => $this->t('Comment'), | |
333 'base' => 'comment', | |
334 'base field' => 'cid', | |
335 'id' => 'standard', | |
336 'label' => $this->t('Last Comment'), | |
337 ], | |
338 ]; | |
339 | |
340 $data['comment_entity_statistics']['last_comment_uid'] = [ | |
341 'title' => $this->t('Last comment uid'), | |
342 'help' => $this->t('The User ID of the author of the last comment of an entity.'), | |
343 'relationship' => [ | |
344 'title' => $this->t('Last comment author'), | |
345 'base' => 'users', | |
346 'base field' => 'uid', | |
347 'id' => 'standard', | |
348 'label' => $this->t('Last comment author'), | |
349 ], | |
350 'filter' => [ | |
351 'id' => 'numeric', | |
352 ], | |
353 'argument' => [ | |
354 'id' => 'numeric', | |
355 ], | |
356 'field' => [ | |
357 'id' => 'numeric', | |
358 ], | |
359 ]; | |
360 | |
361 $data['comment_entity_statistics']['entity_type'] = [ | |
362 'title' => $this->t('Entity type'), | |
363 'help' => $this->t('The entity type to which the comment is a reply to.'), | |
364 'field' => [ | |
365 'id' => 'standard', | |
366 ], | |
367 'filter' => [ | |
368 'id' => 'string', | |
369 ], | |
370 'argument' => [ | |
371 'id' => 'string', | |
372 ], | |
373 'sort' => [ | |
374 'id' => 'standard', | |
375 ], | |
376 ]; | |
377 $data['comment_entity_statistics']['field_name'] = [ | |
378 'title' => $this->t('Comment field name'), | |
379 'help' => $this->t('The field name from which the comment originated.'), | |
380 'field' => [ | |
381 'id' => 'standard', | |
382 ], | |
383 'filter' => [ | |
384 'id' => 'string', | |
385 ], | |
386 'argument' => [ | |
387 'id' => 'string', | |
388 ], | |
389 'sort' => [ | |
390 'id' => 'standard', | |
391 ], | |
392 ]; | |
393 | |
394 return $data; | |
395 } | |
396 | |
397 } |