annotate core/modules/comment/src/CommentViewsData.php @ 19:fa3358dc1485 tip

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