CommentViewsData::getViewsData

public CommentViewsData::getViewsData()

Returns views data for the entity type.

Return value

array Views data in the format of hook_views_data().

Overrides EntityViewsData::getViewsData

File

core/modules/comment/src/CommentViewsData.php, line 15

Class

CommentViewsData
Provides views data for the comment entity type.

Namespace

Drupal\comment

Code

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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
public function getViewsData() {
  $data = parent::getViewsData();
 
  $data['comment_field_data']['table']['base']['help'] = $this->t('Comments are responses to content.');
  $data['comment_field_data']['table']['base']['access query tag'] = 'comment_access';
 
  $data['comment_field_data']['table']['wizard_id'] = 'comment';
 
  $data['comment_field_data']['subject']['title'] = $this->t('Title');
  $data['comment_field_data']['subject']['help'] = $this->t('The title of the comment.');
 
  $data['comment_field_data']['name']['title'] = $this->t('Author');
  $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.");
  $data['comment_field_data']['name']['field']['default_formatter'] = 'comment_username';
 
  $data['comment_field_data']['homepage']['title'] = $this->t("Author's website");
  $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.");
 
  $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.');
 
  $data['comment_field_data']['created']['title'] = $this->t('Post date');
  $data['comment_field_data']['created']['help'] = $this->t('Date and time of when the comment was created.');
 
  $data['comment_field_data']['created_fulldata'] = array(
    'title' => $this->t('Created date'),
    'help' => $this->t('Date in the form of CCYYMMDD.'),
    'argument' => array(
      'field' => 'created',
      'id' => 'date_fulldate',
    ),
  );
 
  $data['comment_field_data']['created_year_month'] = array(
    'title' => $this->t('Created year + month'),
    'help' => $this->t('Date in the form of YYYYMM.'),
    'argument' => array(
      'field' => 'created',
      'id' => 'date_year_month',
    ),
  );
 
  $data['comment_field_data']['created_year'] = array(
    'title' => $this->t('Created year'),
    'help' => $this->t('Date in the form of YYYY.'),
    'argument' => array(
      'field' => 'created',
      'id' => 'date_year',
    ),
  );
 
  $data['comment_field_data']['created_month'] = array(
    'title' => $this->t('Created month'),
    'help' => $this->t('Date in the form of MM (01 - 12).'),
    'argument' => array(
      'field' => 'created',
      'id' => 'date_month',
    ),
  );
 
  $data['comment_field_data']['created_day'] = array(
    'title' => $this->t('Created day'),
    'help' => $this->t('Date in the form of DD (01 - 31).'),
    'argument' => array(
      'field' => 'created',
      'id' => 'date_day',
    ),
  );
 
  $data['comment_field_data']['created_week'] = array(
    'title' => $this->t('Created week'),
    'help' => $this->t('Date in the form of WW (01 - 53).'),
    'argument' => array(
      'field' => 'created',
      'id' => 'date_week',
    ),
  );
 
  $data['comment_field_data']['changed']['title'] = $this->t('Updated date');
  $data['comment_field_data']['changed']['help'] = $this->t('Date and time of when the comment was last updated.');
 
  $data['comment_field_data']['changed_fulldata'] = array(
    'title' => $this->t('Changed date'),
    'help' => $this->t('Date in the form of CCYYMMDD.'),
    'argument' => array(
      'field' => 'changed',
      'id' => 'date_fulldate',
    ),
  );
 
  $data['comment_field_data']['changed_year_month'] = array(
    'title' => $this->t('Changed year + month'),
    'help' => $this->t('Date in the form of YYYYMM.'),
    'argument' => array(
      'field' => 'changed',
      'id' => 'date_year_month',
    ),
  );
 
  $data['comment_field_data']['changed_year'] = array(
    'title' => $this->t('Changed year'),
    'help' => $this->t('Date in the form of YYYY.'),
    'argument' => array(
      'field' => 'changed',
      'id' => 'date_year',
    ),
  );
 
  $data['comment_field_data']['changed_month'] = array(
    'title' => $this->t('Changed month'),
    'help' => $this->t('Date in the form of MM (01 - 12).'),
    'argument' => array(
      'field' => 'changed',
      'id' => 'date_month',
    ),
  );
 
  $data['comment_field_data']['changed_day'] = array(
    'title' => $this->t('Changed day'),
    'help' => $this->t('Date in the form of DD (01 - 31).'),
    'argument' => array(
      'field' => 'changed',
      'id' => 'date_day',
    ),
  );
 
  $data['comment_field_data']['changed_week'] = array(
    'title' => $this->t('Changed week'),
    'help' => $this->t('Date in the form of WW (01 - 53).'),
    'argument' => array(
      'field' => 'changed',
      'id' => 'date_week',
    ),
  );
 
  $data['comment_field_data']['status']['title'] = $this->t('Approved status');
  $data['comment_field_data']['status']['help'] = $this->t('Whether the comment is approved (or still in the moderation queue).');
  $data['comment_field_data']['status']['filter']['label'] = $this->t('Approved comment status');
  $data['comment_field_data']['status']['filter']['type'] = 'yes-no';
 
  $data['comment']['approve_comment'] = array(
    'field' => array(
      'title' => $this->t('Link to approve comment'),
      'help' => $this->t('Provide a simple link to approve the comment.'),
      'id' => 'comment_link_approve',
    ),
  );
 
  $data['comment']['replyto_comment'] = array(
    'field' => array(
      'title' => $this->t('Link to reply-to comment'),
      'help' => $this->t('Provide a simple link to reply to the comment.'),
      'id' => 'comment_link_reply',
    ),
  );
 
  $data['comment_field_data']['thread']['field'] = array(
    'title' => $this->t('Depth'),
    'help' => $this->t('Display the depth of the comment if it is threaded.'),
    'id' => 'comment_depth',
  );
  $data['comment_field_data']['thread']['sort'] = array(
    'title' => $this->t('Thread'),
    'help' => $this->t('Sort by the threaded order. This will keep child comments together with their parents.'),
    'id' => 'comment_thread',
  );
  unset($data['comment_field_data']['thread']['filter']);
  unset($data['comment_field_data']['thread']['argument']);
 
  $entities_types = \Drupal::entityManager()->getDefinitions();
 
  // Provide a relationship for each entity type except comment.
  foreach ($entities_types as $type => $entity_type) {
    if ($type == 'comment' || !$entity_type->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface') || !$entity_type->getBaseTable()) {
      continue;
    }
    if ($fields = \Drupal::service('comment.manager')->getFields($type)) {
      $data['comment_field_data'][$type] = array(
        'relationship' => array(
          'title' => $entity_type->getLabel(),
          'help' => $this->t('The @entity_type to which the comment is a reply to.', array('@entity_type' => $entity_type->getLabel())),
          'base' => $entity_type->getDataTable() ? : $entity_type->getBaseTable(),
          'base field' => $entity_type->getKey('id'),
          'relationship field' => 'entity_id',
          'id' => 'standard',
          'label' => $entity_type->getLabel(),
          'extra' => array(
            array(
              'field' => 'entity_type',
              'value' => $type,
              'table' => 'comment_field_data'
            ),
          ),
        ),
      );
    }
  }
 
  $data['comment_field_data']['uid']['title'] = $this->t('Author uid');
  $data['comment_field_data']['uid']['help'] = $this->t('If you need more fields than the uid add the comment: author relationship');
  $data['comment_field_data']['uid']['relationship']['title'] = $this->t('Author');
  $data['comment_field_data']['uid']['relationship']['help'] = $this->t("The User ID of the comment's author.");
  $data['comment_field_data']['uid']['relationship']['label'] = $this->t('author');
 
  $data['comment_field_data']['pid']['title'] = $this->t('Parent CID');
  $data['comment_field_data']['pid']['relationship']['title'] = $this->t('Parent comment');
  $data['comment_field_data']['pid']['relationship']['help'] = $this->t('The parent comment');
  $data['comment_field_data']['pid']['relationship']['label'] = $this->t('parent');
 
  // Define the base group of this table. Fields that don't have a group defined
  // will go into this field by default.
  $data['comment_entity_statistics']['table']['group'] = $this->t('Comment Statistics');
 
  // Provide a relationship for each entity type except comment.
  foreach ($entities_types as $type => $entity_type) {
    if ($type == 'comment' || !$entity_type->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface') || !$entity_type->getBaseTable()) {
      continue;
    }
    // This relationship does not use the 'field id' column, if the entity has
    // multiple comment-fields, then this might introduce duplicates, in which
    // case the site-builder should enable aggregation and SUM the comment_count
    // field. We cannot create a relationship from the base table to
    // {comment_entity_statistics} for each field as multiple joins between
    // the same two tables is not supported.
    if (\Drupal::service('comment.manager')->getFields($type)) {
      $data['comment_entity_statistics']['table']['join'][$entity_type->getDataTable() ? : $entity_type->getBaseTable()] = array(
        'type' => 'INNER',
        'left_field' => $entity_type->getKey('id'),
        'field' => 'entity_id',
        'extra' => array(
          array(
            'field' => 'entity_type',
            'value' => $type,
          ),
        ),
      );
    }
  }
 
  $data['comment_entity_statistics']['last_comment_timestamp'] = array(
    'title' => $this->t('Last comment time'),
    'help' => $this->t('Date and time of when the last comment was posted.'),
    'field' => array(
      'id' => 'comment_last_timestamp',
    ),
    'sort' => array(
      'id' => 'date',
    ),
    'filter' => array(
      'id' => 'date',
    ),
  );
 
  $data['comment_entity_statistics']['last_comment_name'] = array(
    'title' => $this->t("Last comment author"),
    'help' => $this->t('The name of the author of the last posted comment.'),
    'field' => array(
      'id' => 'comment_ces_last_comment_name',
      'no group by' => TRUE,
    ),
    'sort' => array(
      'id' => 'comment_ces_last_comment_name',
      'no group by' => TRUE,
    ),
  );
 
  $data['comment_entity_statistics']['comment_count'] = array(
    'title' => $this->t('Comment count'),
    'help' => $this->t('The number of comments an entity has.'),
    'field' => array(
      'id' => 'numeric',
    ),
    'filter' => array(
      'id' => 'numeric',
    ),
    'sort' => array(
      'id' => 'standard',
    ),
    'argument' => array(
      'id' => 'standard',
    ),
  );
 
  $data['comment_entity_statistics']['last_updated'] = array(
    'title' => $this->t('Updated/commented date'),
    'help' => $this->t('The most recent of last comment posted or entity updated time.'),
    'field' => array(
      'id' => 'comment_ces_last_updated',
      'no group by' => TRUE,
    ),
    'sort' => array(
      'id' => 'comment_ces_last_updated',
      'no group by' => TRUE,
    ),
    'filter' => array(
      'id' => 'comment_ces_last_updated',
    ),
  );
 
  $data['comment_entity_statistics']['cid'] = array(
    'title' => $this->t('Last comment CID'),
    'help' => $this->t('Display the last comment of an entity'),
    'relationship' => array(
      'title' => $this->t('Last comment'),
      'help' => $this->t('The last comment of an entity.'),
      'group' => $this->t('Comment'),
      'base' => 'comment',
      'base field' => 'cid',
      'id' => 'standard',
      'label' => $this->t('Last Comment'),
    ),
  );
 
  $data['comment_entity_statistics']['last_comment_uid'] = array(
    'title' => $this->t('Last comment uid'),
    'help' => $this->t('The User ID of the author of the last comment of an entity.'),
    'relationship' => array(
      'title' => $this->t('Last comment author'),
      'base' => 'users',
      'base field' => 'uid',
      'id' => 'standard',
      'label' => $this->t('Last comment author'),
    ),
    'filter' => array(
      'id' => 'numeric',
    ),
    'argument' => array(
      'id' => 'numeric',
    ),
    'field' => array(
      'id' => 'numeric',
    ),
  );
 
  $data['comment_entity_statistics']['entity_type'] = array(
    'title' => $this->t('Entity type'),
    'help' => $this->t('The entity type to which the comment is a reply to.'),
    'field' => array(
      'id' => 'standard',
    ),
    'filter' => array(
      'id' => 'string',
    ),
    'argument' => array(
      'id' => 'string',
    ),
    'sort' => array(
      'id' => 'standard',
    ),
  );
  $data['comment_entity_statistics']['field_name'] = array(
    'title' => $this->t('Comment field name'),
    'help' => $this->t('The field name from which the comment originated.'),
    'field' => array(
      'id' => 'standard',
    ),
    'filter' => array(
      'id' => 'string',
    ),
    'argument' => array(
      'id' => 'string',
    ),
    'sort' => array(
      'id' => 'standard',
    ),
  );
 
  return $data;
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.