comparison core/modules/comment/comment.views.inc @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c75dbcec494b
1 <?php
2
3 /**
4 * @file
5 * Provide views data for comment.module.
6 */
7
8 use Drupal\Core\Entity\ContentEntityInterface;
9
10 /**
11 * Implements hook_views_data_alter().
12 */
13 function comment_views_data_alter(&$data) {
14 // New comments are only supported for node table because it requires the
15 // history table.
16 $data['node']['new_comments'] = [
17 'title' => t('New comments'),
18 'help' => t('The number of new comments on the node.'),
19 'field' => [
20 'id' => 'node_new_comments',
21 'no group by' => TRUE,
22 ],
23 ];
24
25 // Provide a integration for each entity type except comment.
26 foreach (\Drupal::entityManager()->getDefinitions() as $entity_type_id => $entity_type) {
27 if ($entity_type_id == 'comment' || !$entity_type->entityClassImplements(ContentEntityInterface::class) || !$entity_type->getBaseTable()) {
28 continue;
29 }
30 $fields = \Drupal::service('comment.manager')->getFields($entity_type_id);
31 $base_table = $entity_type->getDataTable() ?: $entity_type->getBaseTable();
32 $args = ['@entity_type' => $entity_type_id];
33
34 if ($fields) {
35 $data[$base_table]['comments_link'] = [
36 'field' => [
37 'title' => t('Add comment link'),
38 'help' => t('Display the standard add comment link used on regular @entity_type, which will only display if the viewing user has access to add a comment.', $args),
39 'id' => 'comment_entity_link',
40 ],
41 ];
42
43 // Multilingual properties are stored in data table.
44 if (!($table = $entity_type->getDataTable())) {
45 $table = $entity_type->getBaseTable();
46 }
47 $data[$table]['uid_touch'] = [
48 'title' => t('User posted or commented'),
49 'help' => t('Display nodes only if a user posted the @entity_type or commented on the @entity_type.', $args),
50 'argument' => [
51 'field' => 'uid',
52 'name table' => 'users_field_data',
53 'name field' => 'name',
54 'id' => 'argument_comment_user_uid',
55 'no group by' => TRUE,
56 'entity_type' => $entity_type_id,
57 'entity_id' => $entity_type->getKey('id'),
58 ],
59 'filter' => [
60 'field' => 'uid',
61 'name table' => 'users_field_data',
62 'name field' => 'name',
63 'id' => 'comment_user_uid',
64 'entity_type' => $entity_type_id,
65 'entity_id' => $entity_type->getKey('id'),
66 ],
67 ];
68
69 foreach ($fields as $field_name => $field) {
70 $data[$base_table][$field_name . '_cid'] = [
71 'title' => t('Comments of the @entity_type using field: @field_name', $args + ['@field_name' => $field_name]),
72 'help' => t('Relate all comments on the @entity_type. This will create 1 duplicate record for every comment. Usually if you need this it is better to create a comment view.', $args),
73 'relationship' => [
74 'group' => t('Comment'),
75 'label' => t('Comments'),
76 'base' => 'comment_field_data',
77 'base field' => 'entity_id',
78 'relationship field' => $entity_type->getKey('id'),
79 'id' => 'standard',
80 'extra' => [
81 [
82 'field' => 'entity_type',
83 'value' => $entity_type_id,
84 ],
85 [
86 'field' => 'field_name',
87 'value' => $field_name,
88 ],
89 ],
90 ],
91 ];
92 }
93 }
94 }
95 }