diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php index 23e8a1100e..08642a06b9 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php @@ -117,7 +117,7 @@ public function viewElements(FieldItemListInterface $items, $langcode) { $elements = []; $url = NULL; if ($this->getSetting('link_to_entity')) { - // For the default revision this falls back to 'canonical' + // For the default revision this falls back to 'canonical'. $url = $this->getEntityUrl($items->getEntity()); } diff --git a/core/modules/comment/config/optional/views.view.comment.yml b/core/modules/comment/config/optional/views.view.comment.yml index 12b5c01b73..427cb52e24 100644 --- a/core/modules/comment/config/optional/views.view.comment.yml +++ b/core/modules/comment/config/optional/views.view.comment.yml @@ -249,10 +249,10 @@ display: entity_type: comment entity_field: subject plugin_id: field - uid: - id: uid + name: + id: name table: comment_field_data - field: uid + field: name relationship: none group_type: group admin_label: '' @@ -297,11 +297,10 @@ display: hide_empty: false empty_zero: false hide_alter_empty: true - click_sort_column: target_id - type: entity_reference_label - settings: - link: true - group_column: target_id + click_sort_column: value + type: comment_username + settings: { } + group_column: value group_columns: { } group_rows: true delta_limit: 0 @@ -312,7 +311,7 @@ display: separator: ', ' field_api_classes: false entity_type: comment - entity_field: uid + entity_field: name plugin_id: field entity_id: id: entity_id @@ -795,10 +794,10 @@ display: entity_type: comment entity_field: subject plugin_id: field - uid: - id: uid + name: + id: name table: comment_field_data - field: uid + field: name relationship: none group_type: group admin_label: '' @@ -843,11 +842,10 @@ display: hide_empty: false empty_zero: false hide_alter_empty: true - click_sort_column: target_id - type: entity_reference_label - settings: - link: true - group_column: target_id + click_sort_column: value + type: comment_username + settings: { } + group_column: value group_columns: { } group_rows: true delta_limit: 0 @@ -858,7 +856,7 @@ display: separator: ', ' field_api_classes: false entity_type: comment - entity_field: uid + entity_field: name plugin_id: field entity_id: id: entity_id diff --git a/core/modules/comment/src/Plugin/Field/FieldFormatter/CommentPermalinkFormatter.php b/core/modules/comment/src/Plugin/Field/FieldFormatter/CommentPermalinkFormatter.php index d579243e17..0f344126d2 100644 --- a/core/modules/comment/src/Plugin/Field/FieldFormatter/CommentPermalinkFormatter.php +++ b/core/modules/comment/src/Plugin/Field/FieldFormatter/CommentPermalinkFormatter.php @@ -31,15 +31,13 @@ class CommentPermalinkFormatter extends StringFormatter { * {@inheritdoc} */ protected function getEntityUrl(EntityInterface $comment) { - /** @var $comment \Drupal\comment\CommentInterface */ - $body = ''; - if (!empty($comment->comment_body->value)) { - $body = $comment->comment_body->value; - } + /* @var $comment \Drupal\comment\CommentInterface */ $comment_permalink = $comment->permalink(); - $attributes = $comment_permalink->getOption('attributes') ?: []; - $attributes += ['title' => Unicode::truncate($body, 128)]; - $comment_permalink->setOption('attributes', $attributes); + if ($comment->hasField('comment_body') && ($body = $comment->get('comment_body')->value)) { + $attributes = $comment_permalink->getOption('attributes') ?: []; + $attributes += ['title' => Unicode::truncate($body, 128)]; + $comment_permalink->setOption('attributes', $attributes); + } return $comment_permalink; } diff --git a/core/modules/comment/src/Tests/Views/CommentAdminTest.php b/core/modules/comment/src/Tests/Views/CommentAdminTest.php index ea868a7b21..50ac0c919e 100644 --- a/core/modules/comment/src/Tests/Views/CommentAdminTest.php +++ b/core/modules/comment/src/Tests/Views/CommentAdminTest.php @@ -9,6 +9,7 @@ use Drupal\Component\Render\FormattableMarkup; use Drupal\comment\Tests\CommentTestBase as CommentWebTestBase; use Drupal\Component\Utility\Html; +use Drupal\Component\Utility\Unicode; use Drupal\user\RoleInterface; use Drupal\views\Views; @@ -52,10 +53,13 @@ public function testApprovalAdminInterface() { $this->drupalLogout(); // Post anonymous comment without contact info. - $subject = $this->randomMachineName(); - $body = $this->randomMachineName(); - // Set $contact to true so that it won't check for id and message. - $this->postComment($this->node, $body, $subject, TRUE); + $body = $this->getRandomGenerator()->sentences(4); + $subject = Unicode::truncate(trim(Html::decodeEntities(strip_tags($body))), 29, TRUE, TRUE); + $author_name = $this->randomMachineName(); + $this->drupalPostForm('comment/reply/node/' . $this->node->id() . '/comment', [ + 'name' => $author_name, + 'comment_body[0][value]' => $body, + ], t('Save')); $this->assertText(t('Your comment has been queued for review by site administrators and will be published after approval.'), 'Comment requires approval.'); // Get unapproved comment id. @@ -105,6 +109,23 @@ public function testApprovalAdminInterface() { // Test message when no comments selected. $this->drupalPostForm('admin/content/comment', [], t('Apply to selected items')); $this->assertText(t('Select one or more comments to perform the update on.')); + + $subject_link = $this->xpath('//table/tbody/tr/td/a[contains(@href, :href) and contains(@title, :title) and text()=:text]', [ + ':href' => $comments[0]->permalink()->toString(), + ':title' => Unicode::truncate($comments[0]->get('comment_body')->value, 128), + ':text' => $comments[0]->getSubject(), + ]); + $this->assertTrue(!empty($subject_link), 'Comment listing shows the correct subject link.'); + $this->assertText($author_name . ' (not verified)', 'Anonymous author name is displayed correctly.'); + + $subject_link = $this->xpath('//table/tbody/tr/td/a[contains(@href, :href) and contains(@title, :title) and text()=:text]', [ + ':href' => $anonymous_comment4->permalink()->toString(), + ':title' => Unicode::truncate($body, 128), + ':text' => $subject, + ]); + $this->assertTrue(!empty($subject_link), 'Comment listing shows the correct subject link.'); + $this->assertText($author_name . ' (not verified)', 'Anonymous author name is displayed correctly.'); + // Delete multiple comments in one operation. $edit = [ 'action' => 'comment_delete_action', @@ -168,6 +189,17 @@ public function testCommentedEntityLabel() { // Login as admin to test the admin comment page. $this->drupalLogin($this->adminUser); $this->drupalGet('admin/content/comment'); + + $comment_author_link = $this->xpath('//table/tbody/tr[1]/td/a[contains(@href, :href) and text()=:text]', [ + ':href' => $this->webUser->toUrl()->toString(), + ':text' => $this->webUser->label(), + ]); + $this->assertTrue(!empty($comment_author_link), 'Comment listing links to comment author.'); + $comment_author_link = $this->xpath('//table/tbody/tr[2]/td/a[contains(@href, :href) and text()=:text]', [ + ':href' => $this->webUser->toUrl()->toString(), + ':text' => $this->webUser->label(), + ]); + $this->assertTrue(!empty($comment_author_link), 'Comment listing links to comment author.'); // Admin page contains label of both entities. $this->assertText(Html::escape($this->node->label()), 'Node title is visible.'); $this->assertText(Html::escape($block_content->label()), 'Block content label is visible.');