diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 9ad36259a3..e551a4eb05 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -12,6 +12,7 @@ use Drupal\comment\CommentInterface; use Drupal\comment\Entity\CommentType; +use Drupal\Component\Utility\Unicode; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\Core\Entity\Entity\EntityViewMode; @@ -72,13 +73,13 @@ function comment_help($route_name, RouteMatchInterface $route_match) { * Entity URI callback. */ function comment_uri(CommentInterface $comment) { - return new Url( - 'entity.comment.canonical', - [ - 'comment' => $comment->id(), - ], - ['fragment' => 'comment-' . $comment->id()] - ); + $comment_permalink = $comment->permalink(); + 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/tests/src/Functional/CommentBlockTest.php b/core/modules/comment/tests/src/Functional/CommentBlockTest.php index 7ca4d18dd6..bd3b54481c 100644 --- a/core/modules/comment/tests/src/Functional/CommentBlockTest.php +++ b/core/modules/comment/tests/src/Functional/CommentBlockTest.php @@ -73,7 +73,7 @@ public function testRecentCommentBlock() { $this->assertNoText($comments[10]->getSubject()); for ($i = 0; $i < 10; $i++) { $this->assertSession()->pageTextContains($comments[$i]->getSubject()); - $this->assertSession()->linkByHrefExists("comment/{$comments[$i]->id()}#comment-{$comments[$i]->id()}"); + $this->assertSession()->linkByHrefExists($comments[$i]->permalink()->toString()); if ($i > 1) { $previous_position = $position; $position = strpos($this->getSession()->getPage()->getContent(), $comments[$i]->getSubject());