diff --git a/core/modules/comment/config/optional/views.view.comments_recent.yml b/core/modules/comment/config/optional/views.view.comments_recent.yml index dd4ba6a..a15ecd1 100644 --- a/core/modules/comment/config/optional/views.view.comments_recent.yml +++ b/core/modules/comment/config/optional/views.view.comments_recent.yml @@ -65,7 +65,10 @@ display: table: comment_field_data field: subject relationship: none - plugin_id: comment + type: string + settings: + link_to_entity: true + plugin_id: field group_type: group admin_label: '' label: '' @@ -109,8 +112,6 @@ display: hide_empty: false empty_zero: false hide_alter_empty: true - link_to_comment: true - link_to_entity: false entity_type: comment entity_field: subject changed: @@ -215,9 +216,7 @@ display: admin_label: '' order: DESC exposed: false - expose: - label: '' - plugin_id: standard + plugin_id: field entity_type: comment entity_field: cid title: 'Recent comments' diff --git a/core/modules/comment/config/schema/comment.views.schema.yml b/core/modules/comment/config/schema/comment.views.schema.yml index 51953ad..33f3564 100644 --- a/core/modules/comment/config/schema/comment.views.schema.yml +++ b/core/modules/comment/config/schema/comment.views.schema.yml @@ -4,17 +4,6 @@ views.argument.argument_comment_user_uid: type: views_argument label: 'Commented user ID' -views.field.comment: - type: views_field - label: 'Comment' - mapping: - link_to_comment: - type: boolean - label: 'Link this field to its comment' - link_to_entity: - type: boolean - label: 'Link field to the entity if there is no comment' - views.field.comment_depth: type: views_field label: 'Comment depth' diff --git a/core/modules/comment/src/CommentViewsData.php b/core/modules/comment/src/CommentViewsData.php index f84e221..6784084 100644 --- a/core/modules/comment/src/CommentViewsData.php +++ b/core/modules/comment/src/CommentViewsData.php @@ -27,9 +27,6 @@ public function getViewsData() { $data['comment_field_data']['subject']['title'] = t('Title'); $data['comment_field_data']['subject']['help'] = t('The title of the comment.'); - $data['comment_field_data']['subject']['field']['id'] = 'comment'; - - $data['comment_field_data']['cid']['field']['id'] = 'comment'; $data['comment_field_data']['name']['title'] = t('Author'); $data['comment_field_data']['name']['help'] = t("The name of the comment's author. Can be rendered as a link to the author's homepage."); diff --git a/core/modules/comment/src/Plugin/views/field/Comment.php b/core/modules/comment/src/Plugin/views/field/Comment.php deleted file mode 100644 index 1b52b86..0000000 --- a/core/modules/comment/src/Plugin/views/field/Comment.php +++ /dev/null @@ -1,122 +0,0 @@ -options['link_to_comment'])) { - $this->additional_fields['cid'] = 'cid'; - $this->additional_fields['entity_id'] = array( - 'table' => 'comment_field_data', - 'field' => 'entity_id' - ); - $this->additional_fields['entity_type'] = array( - 'table' => 'comment_field_data', - 'field' => 'entity_type' - ); - } - } - - /** - * {@inheritdoc} - */ - protected function defineOptions() { - $options = parent::defineOptions(); - $options['link_to_comment'] = array('default' => TRUE); - $options['link_to_entity'] = array('default' => FALSE); - - return $options; - } - - /** - * Provide link-to-comment option - */ - public function buildOptionsForm(&$form, FormStateInterface $form_state) { - $form['link_to_comment'] = array( - '#title' => $this->t('Link this field to its comment'), - '#description' => $this->t("Enable to override this field's links."), - '#type' => 'checkbox', - '#default_value' => $this->options['link_to_comment'], - ); - $form['link_to_entity'] = array( - '#title' => $this->t('Link field to the entity if there is no comment'), - '#type' => 'checkbox', - '#default_value' => $this->options['link_to_entity'], - ); - parent::buildOptionsForm($form, $form_state); - } - - /** - * Render whatever the data is as a link to the comment or its node. - * - * @param string $data - * The XSS safe string for the link text. - * @param \Drupal\views\ResultRow $values - * The values retrieved from a single row of a view's query result. - * - * @return string - * Returns a string for the link text. - */ - protected function renderLink($data, ResultRow $values) { - if (!empty($this->options['link_to_comment'])) { - $this->options['alter']['make_link'] = TRUE; - $cid = $this->getValue($values, 'cid'); - if (!empty($cid)) { - $this->options['alter']['url'] = Url::fromRoute('entity.comment.canonical', ['comment' => $cid]); - $this->options['alter']['fragment'] = "comment-" . $cid; - } - // If there is no comment link to the entity. - elseif ($this->options['link_to_entity']) { - $entity_id = $this->getValue($values, 'entity_id'); - $entity_type = $this->getValue($values, 'entity_type'); - $entity = entity_load($entity_type, $entity_id); - $this->options['alter']['url'] = $entity->urlInfo(); - } - } - - return $data; - } - - /** - * {@inheritdoc} - */ - public function render(ResultRow $values) { - $value = $this->getValue($values); - return $this->renderLink($this->sanitizeValue($value), $values); - } - -} diff --git a/core/modules/comment/src/Plugin/views/field/Depth.php b/core/modules/comment/src/Plugin/views/field/Depth.php index a66a80c..c69fe2c 100644 --- a/core/modules/comment/src/Plugin/views/field/Depth.php +++ b/core/modules/comment/src/Plugin/views/field/Depth.php @@ -7,7 +7,7 @@ namespace Drupal\comment\Plugin\views\field; -use Drupal\views\Plugin\views\field\FieldPluginBase; +use Drupal\views\Plugin\views\field\Field; use Drupal\views\ResultRow; /** @@ -17,15 +17,20 @@ * * @ViewsField("comment_depth") */ -class Depth extends FieldPluginBase { +class Depth extends Field { /** * {@inheritdoc} */ - public function render(ResultRow $values) { - // Work out the depth of this comment. - $comment_thread = $this->getValue($values); - return count(explode('.', $comment_thread)) - 1; + public function getItems(ResultRow $values) { + $items = parent::getItems($values); + + foreach ($items as &$item) { + // Work out the depth of this comment. + $comment_thread = $item['rendered']['#markup']; + $item['rendered']['#markup'] = count(explode('.', $comment_thread)) - 1; + } + return $items; } } diff --git a/core/modules/comment/src/Plugin/views/field/NodeComment.php b/core/modules/comment/src/Plugin/views/field/NodeComment.php deleted file mode 100644 index 45a9deb..0000000 --- a/core/modules/comment/src/Plugin/views/field/NodeComment.php +++ /dev/null @@ -1,39 +0,0 @@ -getValue($values); - switch ($value) { - case CommentItemInterface::HIDDEN: - default: - return $this->t('Hidden'); - case CommentItemInterface::CLOSED: - return $this->t('Closed'); - case CommentItemInterface::OPEN: - return $this->t('Open'); - } - } - -} diff --git a/core/modules/comment/src/Plugin/views/wizard/Comment.php b/core/modules/comment/src/Plugin/views/wizard/Comment.php index aa89369..35c3167 100644 --- a/core/modules/comment/src/Plugin/views/wizard/Comment.php +++ b/core/modules/comment/src/Plugin/views/wizard/Comment.php @@ -101,8 +101,9 @@ protected function defaultDisplayOptions() { $display_options['fields']['subject']['alter']['html'] = 0; $display_options['fields']['subject']['hide_empty'] = 0; $display_options['fields']['subject']['empty_zero'] = 0; - $display_options['fields']['subject']['link_to_comment'] = 1; - $display_options['fields']['subject']['plugin_id'] = 'comment'; + $display_options['fields']['subject']['plugin_id'] = 'field'; + $display_options['fields']['subject']['type'] = 'string'; + $display_options['fields']['subject']['settings'] = ['link_to_entity' => TRUE]; return $display_options; } diff --git a/core/modules/comment/src/Tests/Views/CommentRestExportTest.php b/core/modules/comment/src/Tests/Views/CommentRestExportTest.php index 8cc432d..ecf1a54 100644 --- a/core/modules/comment/src/Tests/Views/CommentRestExportTest.php +++ b/core/modules/comment/src/Tests/Views/CommentRestExportTest.php @@ -45,6 +45,9 @@ protected function setUp() { ); $this->comment = entity_create('comment', $comment); $this->comment->save(); + + $user = $this->drupalCreateUser(['access comments']); + $this->drupalLogin($user); } diff --git a/core/modules/comment/src/Tests/Views/DefaultViewRecentCommentsTest.php b/core/modules/comment/src/Tests/Views/DefaultViewRecentCommentsTest.php index dbff0d9..89b03b3 100644 --- a/core/modules/comment/src/Tests/Views/DefaultViewRecentCommentsTest.php +++ b/core/modules/comment/src/Tests/Views/DefaultViewRecentCommentsTest.php @@ -114,19 +114,20 @@ protected function setUp() { * Tests the block defined by the comments_recent view. */ public function testBlockDisplay() { + $user = $this->drupalCreateUser(['access comments']); + $this->drupalLogin($user); + $view = Views::getView('comments_recent'); $view->setDisplay('block_1'); $this->executeView($view); $map = array( - 'comment_field_data_entity_id' => 'entity_id', - 'comment_field_data_subject' => 'subject', + 'subject' => 'subject', 'cid' => 'cid', 'comment_field_data_created' => 'created' ); $expected_result = array(); foreach (array_values($this->commentsCreated) as $key => $comment) { - $expected_result[$key]['entity_id'] = $comment->getCommentedEntityId(); $expected_result[$key]['subject'] = $comment->getSubject(); $expected_result[$key]['cid'] = $comment->id(); $expected_result[$key]['created'] = $comment->getCreatedTime(); diff --git a/core/modules/comment/src/Tests/Views/WizardTest.php b/core/modules/comment/src/Tests/Views/WizardTest.php index 3d9c730..d27098c 100644 --- a/core/modules/comment/src/Tests/Views/WizardTest.php +++ b/core/modules/comment/src/Tests/Views/WizardTest.php @@ -78,6 +78,9 @@ public function testCommentWizard() { $this->drupalPostForm(NULL, $view, t('Save and edit')); $this->assertUrl('admin/structure/views/view/' . $view['id'], array(), 'Make sure the view saving was successful and the browser got redirected to the edit page.'); + $user = $this->drupalCreateUser(['access comments']); + $this->drupalLogin($user); + $view = Views::getView($view['id']); $view->initHandlers(); $row = $view->display_handler->getOption('row'); diff --git a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_rest.yml b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_rest.yml index 0c53369..d9a2d26 100644 --- a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_rest.yml +++ b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_rest.yml @@ -140,9 +140,10 @@ display: hide_empty: false empty_zero: false hide_alter_empty: true - link_to_comment: true - link_to_entity: false - plugin_id: comment + type: string + settings: + link_to_entity: false + plugin_id: field name: id: name table: comment_field_data diff --git a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_row.yml b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_row.yml index 6063d89..f6588b8 100644 --- a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_row.yml +++ b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_row.yml @@ -98,7 +98,6 @@ display: html: false hide_empty: false empty_zero: false - link_to_comment: true relationship: none group_type: group admin_label: '' @@ -113,8 +112,10 @@ display: element_default_classes: true empty: '' hide_alter_empty: true - link_to_entity: false - plugin_id: comment + type: string + settings: + link_to_entity: true + plugin_id: field entity_type: comment entity_field: subject filters: diff --git a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_rss.yml b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_rss.yml index 146e3f4..7fb1644 100644 --- a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_rss.yml +++ b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_rss.yml @@ -45,7 +45,7 @@ display: id: subject table: comment_field_data field: subject - plugin_id: comment + plugin_id: field label: '' alter: alter_text: false @@ -58,7 +58,9 @@ display: html: false hide_empty: false empty_zero: false - link_to_comment: true + type: string + settings: + link_to_entity: true entity_type: comment entity_field: subject filters: { } diff --git a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_field_filters.yml b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_field_filters.yml index 7b848df..60f6554 100644 --- a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_field_filters.yml +++ b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_field_filters.yml @@ -83,7 +83,6 @@ display: html: false hide_empty: false empty_zero: false - link_to_comment: true relationship: none group_type: group admin_label: '' @@ -98,8 +97,10 @@ display: element_default_classes: true empty: '' hide_alter_empty: true - link_to_entity: false - plugin_id: comment + type: string + settings: + link_to_entity: false + plugin_id: field entity_type: comment entity_field: subject filters: diff --git a/core/modules/system/src/Tests/Cache/PageCacheTagsIntegrationTest.php b/core/modules/system/src/Tests/Cache/PageCacheTagsIntegrationTest.php index f48c2de..c36b278 100644 --- a/core/modules/system/src/Tests/Cache/PageCacheTagsIntegrationTest.php +++ b/core/modules/system/src/Tests/Cache/PageCacheTagsIntegrationTest.php @@ -105,6 +105,13 @@ function testPageCacheTags() { 'config:system.site', )); + // Rendering the view block adds the languages cache context. As the + // languages is the parent of the + // languages::LanguageInterface::TYPE_INTERFACE cache context, it will be + // optimized out. + $cache_contexts[] = 'languages'; + unset($cache_contexts[array_search('languages:' . LanguageInterface::TYPE_INTERFACE, $cache_contexts)]); + // Full node page 2. $this->assertPageCacheContextsAndTags($node_2->urlInfo(), $cache_contexts, array( 'rendered', diff --git a/core/modules/views/src/Tests/Entity/FieldEntityTest.php b/core/modules/views/src/Tests/Entity/FieldEntityTest.php index 770f7f0..404434f 100644 --- a/core/modules/views/src/Tests/Entity/FieldEntityTest.php +++ b/core/modules/views/src/Tests/Entity/FieldEntityTest.php @@ -67,6 +67,9 @@ public function testGetEntity() { )); $comment->save(); + $user = $this->drupalCreateUser(['access comments']); + $this->drupalLogin($user); + $view = Views::getView('test_field_get_entity'); $this->executeView($view); $row = $view->result[0]; diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_field_get_entity.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_field_get_entity.yml index 7e20ee7..3613335 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_field_get_entity.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_field_get_entity.yml @@ -27,7 +27,7 @@ display: field: cid id: cid table: comment_field_data - plugin_id: comment + plugin_id: field entity_type: comment entity_field: cid nid: