diff --git a/core/modules/comment/config/optional/views.view.comment.yml b/core/modules/comment/config/optional/views.view.comment.yml index 56c4de3..5ce2d56 100644 --- a/core/modules/comment/config/optional/views.view.comment.yml +++ b/core/modules/comment/config/optional/views.view.comment.yml @@ -79,7 +79,7 @@ display: comment_bulk_form: comment_bulk_form subject: subject name: name - commented_entity_label: commented_entity_label + entity_id: entity_id changed: changed operations: operations info: @@ -102,7 +102,7 @@ display: separator: '' empty_column: false responsive: priority-medium - commented_entity_label: + entity_id: sortable: false default_sort_order: asc align: '' @@ -312,10 +312,10 @@ display: entity_type: comment entity_field: name plugin_id: field - commented_entity_label: - id: commented_entity_label - table: comment - field: commented_entity_label + entity_id: + id: entity_id + table: comment_field_data + field: entity_id relationship: none group_type: group admin_label: '' @@ -360,9 +360,23 @@ display: hide_empty: false empty_zero: false hide_alter_empty: true - link_to_entity: true + click_sort_column: target_id + type: entity_reference_label + settings: + link: true + group_column: target_id + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false entity_type: comment - plugin_id: commented_entity_label + entity_field: entity_id + plugin_id: commented_entity changed: id: changed table: comment_field_data @@ -828,10 +842,10 @@ display: entity_type: comment entity_field: name plugin_id: field - commented_entity_label: - id: commented_entity_label - table: comment - field: commented_entity_label + entity_id: + id: entity_id + table: comment_field_data + field: entity_id relationship: none group_type: group admin_label: '' @@ -876,9 +890,23 @@ display: hide_empty: false empty_zero: false hide_alter_empty: true - link_to_entity: true + click_sort_column: target_id + type: entity_reference_label + settings: + link: true + group_column: target_id + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false entity_type: comment - plugin_id: commented_entity_label + entity_field: entity_id + plugin_id: commented_entity changed: id: changed table: comment_field_data diff --git a/core/modules/comment/config/schema/comment.views.schema.yml b/core/modules/comment/config/schema/comment.views.schema.yml index 9b59207..a46a004 100644 --- a/core/modules/comment/config/schema/comment.views.schema.yml +++ b/core/modules/comment/config/schema/comment.views.schema.yml @@ -20,13 +20,9 @@ views.field.comment_bulk_form: type: views_field_bulk_form label: 'Comment bulk form' -views.field.commented_entity_label: - type: views_field - label: 'Commented entity label' - mapping: - link_to_entity: - type: boolean - label: 'Link to entity' +views.field.commented_entity: + type: views.field.field + label: 'Commented entity' views.field.comment_last_timestamp: type: views.field.date diff --git a/core/modules/comment/src/CommentViewsData.php b/core/modules/comment/src/CommentViewsData.php index 91c97a3..0f2d576 100644 --- a/core/modules/comment/src/CommentViewsData.php +++ b/core/modules/comment/src/CommentViewsData.php @@ -119,13 +119,7 @@ public function getViewsData() { ), ); - $data['comment']['commented_entity_label'] = array( - 'title' => t('Label of commented entity'), - 'help' => t('Provide a label of commented entity.'), - 'field' => array( - 'id' => 'commented_entity_label', - ), - ); + $data['comment_field_data']['entity_id']['field']['id'] = 'commented_entity'; $data['comment']['comment_bulk_form'] = array( 'title' => t('Comment operations bulk form'), diff --git a/core/modules/comment/src/Plugin/views/field/CommentedEntity.php b/core/modules/comment/src/Plugin/views/field/CommentedEntity.php new file mode 100644 index 0000000..98da8f9 --- /dev/null +++ b/core/modules/comment/src/Plugin/views/field/CommentedEntity.php @@ -0,0 +1,45 @@ +getEntity($value)) { + $entity_ids_per_type[$comment->getCommentedEntityTypeId()][] = $comment->getCommentedEntityId(); + } + } + + foreach ($entity_ids_per_type as $type => $ids) { + $this->loadedCommentedEntities[$type] = $this->entityManager->getStorage($type)->loadMultiple($ids); + } + } + +} diff --git a/core/modules/comment/src/Plugin/views/field/CommentedEntityLabel.php b/core/modules/comment/src/Plugin/views/field/CommentedEntityLabel.php deleted file mode 100644 index fca2efb..0000000 --- a/core/modules/comment/src/Plugin/views/field/CommentedEntityLabel.php +++ /dev/null @@ -1,135 +0,0 @@ -entityManager = $manager; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('entity.manager') - ); - } - - /** - * {@inheritdoc} - */ - protected function defineOptions() { - $options = parent::defineOptions(); - $options['link_to_entity'] = array('default' => FALSE); - return $options; - } - - /** - * {@inheritdoc} - */ - public function buildOptionsForm(&$form, FormStateInterface $form_state) { - $form['link_to_entity'] = array( - '#title' => $this->t('Link to entity'), - '#description' => $this->t('Make entity label a link to entity page.'), - '#type' => 'checkbox', - '#default_value' => !empty($this->options['link_to_entity']), - ); - parent::buildOptionsForm($form, $form_state); - } - - /** - * {@inheritdoc} - */ - public function query() { - } - - /** - * {@inheritdoc} - */ - public function render(ResultRow $values) { - /** @var \Drupal\comment\CommentInterface $comment */ - if(($comment = $this->getEntity($values)) && isset($this->loadedCommentedEntities[$comment->getCommentedEntityTypeId()]) && isset($this->loadedCommentedEntities[$comment->getCommentedEntityTypeId()][$comment->getCommentedEntityId()])) { - - /** @var $entity \Drupal\Core\Entity\EntityInterface */ - $entity = $this->loadedCommentedEntities[$comment->getCommentedEntityTypeId()][$comment->getCommentedEntityId()]; - - if (!empty($this->options['link_to_entity'])) { - $this->options['alter']['make_link'] = TRUE; - $this->options['alter']['url'] = $entity->urlInfo(); - } - if ($entity->access('view')) { - return $this->sanitizeValue($entity->label()); - } - } - return ''; - } - - /** - * {@inheritdoc} - */ - public function preRender(&$values) { - parent::preRender($values); - - $entity_ids_per_type = array(); - foreach ($values as $value) { - /** @var \Drupal\comment\CommentInterface $comment */ - if ($comment = $this->getEntity($value)) { - $entity_ids_per_type[$comment->getCommentedEntityTypeId()][] = $comment->getCommentedEntityId(); - } - } - - foreach ($entity_ids_per_type as $type => $ids) { - $this->loadedCommentedEntities[$type] = $this->entityManager->getStorage($type)->loadMultiple($ids); - } - } - -} diff --git a/core/modules/comment/src/Tests/Views/CommentAdminTest.php b/core/modules/comment/src/Tests/Views/CommentAdminTest.php index cb2a29a..c91bb29 100644 --- a/core/modules/comment/src/Tests/Views/CommentAdminTest.php +++ b/core/modules/comment/src/Tests/Views/CommentAdminTest.php @@ -113,17 +113,21 @@ function testApprovalAdminInterface() { $this->drupalGet('admin/content/comment'); $this->postComment($this->node, $this->randomMachineName()); $this->drupalLogout(); - $this->commentAdminUser = $this->drupalCreateUser(array( - 'administer comments', - )); - $this->drupalLogin($this->commentAdminUser); + $this->drupalLogin($this->adminUser); $this->drupalGet('admin/content/comment'); - $this->assertText(SafeMarkup::checkPlain($this->node->label()), 'Comment admin can see title of publish node'); + $this->assertText(SafeMarkup::checkPlain($this->node->label()), 'Comment admin can see the title of a publish node'); $this->node->setPublished(FALSE)->save(); $this->assertFalse($this->node->isPublished(), 'Node is unpublished now.'); - drupal_flush_all_caches(); $this->drupalGet('admin/content/comment'); - $this->assertNoText(SafeMarkup::checkPlain($this->node->label()), 'Comment admin cannot see title of unpublish node'); + $this->assertNoText(SafeMarkup::checkPlain($this->node->label()), 'Comment admin cannot see the title of a unpublish node'); + $this->drupalLogout(); + $this->nodeAccessUser = $this->drupalCreateUser(array( + 'administer comments', + 'bypass node access' + )); + $this->drupalLogin($this->nodeAccessUser); + $this->drupalGet('admin/content/comment'); + $this->assertText(SafeMarkup::checkPlain($this->node->label()), 'Comment admin with bypass node access permissions can still see the title of a publish node'); } }