diff --git a/core/modules/comment/comment.routing.yml b/core/modules/comment/comment.routing.yml index 4799400..fea8cc1 100644 --- a/core/modules/comment/comment.routing.yml +++ b/core/modules/comment/comment.routing.yml @@ -37,7 +37,7 @@ comment.approve: entity.comment.canonical: path: '/comment/{comment}' defaults: - _title: 'Comment permalink' + _title_callback: '\Drupal\comment\Controller\CommentController::commentPermalinkTitle' _controller: '\Drupal\comment\Controller\CommentController::commentPermalink' requirements: _entity_access: 'comment.view' diff --git a/core/modules/comment/src/CommentBreadcrumbBuilder.php b/core/modules/comment/src/CommentBreadcrumbBuilder.php index 89644b0..ee5dd6b 100644 --- a/core/modules/comment/src/CommentBreadcrumbBuilder.php +++ b/core/modules/comment/src/CommentBreadcrumbBuilder.php @@ -11,6 +11,7 @@ use Drupal\Core\Link; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; +use Drupal\comment\Entity\Comment; /** * Class to define the comment breadcrumb builder. @@ -22,26 +23,26 @@ class CommentBreadcrumbBuilder implements BreadcrumbBuilderInterface { * {@inheritdoc} */ public function applies(RouteMatchInterface $route_match) { - return ($route_match->getRouteName() == 'comment.reply' && $route_match->getParameter('entity')) || - ($route_match->getRouteName() == 'entity.comment.edit_form' && $route_match->getParameter('comment')) || - ($route_match->getRouteName() == 'entity.comment.delete_form' && $route_match->getParameter('comment')); + return $route_match->getRouteName() == 'comment.reply' && $route_match->getParameter('entity'); } /** * {@inheritdoc} */ public function build(RouteMatchInterface $route_match) { - $breadcrumb = array(); + $breadcrumb = [Link::createFromRoute($this->t('Home'), '')]; - // Figure out the parameter name based on the route. - $param_name = 'comment'; - if ($route_match->getRouteName() == 'comment.reply') { - $param_name = 'entity'; + $entity = $route_match->getParameter('entity'); + $breadcrumb[] = new Link($entity->label(), $entity->urlInfo()); + + if ($pid = $route_match->getParameter('pid')) { + // Display link to parent comment. + // @todo Properly inject storage. + $comment = Comment::load($pid); + // @todo Clean-up permalink in https://www.drupal.org/node/2198041 + $breadcrumb[] = new Link($comment->getSubject(), $comment->urlInfo()); } - $entity = $route_match->getParameter($param_name); - $breadcrumb[] = Link::createFromRoute($this->t('Home'), ''); - $breadcrumb[] = new Link($entity->label(), $entity->urlInfo()); return $breadcrumb; } diff --git a/core/modules/comment/src/Controller/CommentController.php b/core/modules/comment/src/Controller/CommentController.php index 84fbf72..a5be037 100644 --- a/core/modules/comment/src/Controller/CommentController.php +++ b/core/modules/comment/src/Controller/CommentController.php @@ -138,6 +138,20 @@ public function commentPermalink(Request $request, CommentInterface $comment) { } /** + * The _title_callback for the page that renders a single comment. + * + * @param \Drupal\comment\CommentInterface $comment + * The current comment. + * + * @return string + * The translated comment subject. + */ + public function commentPermalinkTitle(CommentInterface $comment) { + // @todo Trim to usable limit. + return $this->entityManager()->getTranslationFromContext($comment)->label(); + } + + /** * Redirects legacy node links to the new path. * * @param \Drupal\Core\Entity\EntityInterface $node diff --git a/core/modules/comment/src/Tests/CommentInterfaceTest.php b/core/modules/comment/src/Tests/CommentInterfaceTest.php index 7d6c2a1..137bcab 100644 --- a/core/modules/comment/src/Tests/CommentInterfaceTest.php +++ b/core/modules/comment/src/Tests/CommentInterfaceTest.php @@ -90,10 +90,15 @@ function testCommentInterface() { $comment = $this->postComment(NULL, $comment->comment_body->value, $comment->getSubject(), array('name' => $this->webUser->getUsername())); $this->assertTrue($comment->getAuthorName() == $this->webUser->getUsername() && $comment->getOwnerId() == $this->webUser->id(), 'Comment author successfully changed to a registered user.'); + // Test breadcrumb on comment add page. + $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment'); + $xpath = '//nav[@class="breadcrumb"]/ol/li[last()]/a'; + $this->assertEqual(current($this->xpath($xpath)), $this->node->label(), 'Last breadcrumb item is equal to node title on comment reply page.'); + // Test breadcrumb on comment reply page. $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment/' . $comment->id()); $xpath = '//nav[@class="breadcrumb"]/ol/li[last()]/a'; - $this->assertEqual(current($this->xpath($xpath)), $this->node->label(), 'Last breadcrumb item is equal to node title on comment reply page.'); + $this->assertEqual(current($this->xpath($xpath)), $comment->getSubject(), 'Last breadcrumb item is equal to comment title on comment reply page.'); // Test breadcrumb on comment edit page. $this->drupalGet('comment/' . $comment->id() . '/edit');