diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 380b804..54bfefa 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -247,7 +247,8 @@ function comment_node_links_alter(array &$node_links, NodeInterface $node, array // @todo Make this configurable from the formatter see // http://drupal.org/node/1901110 - \Drupal::service('comment.link_builder')->buildLinks($node_links, $node, $context); + $links = \Drupal::service('comment.link_builder')->buildCommentedEntityLinks($node, $context); + $node_links += $links; } /** diff --git a/core/modules/comment/src/CommentLinkBuilder.php b/core/modules/comment/src/CommentLinkBuilder.php index a3d30a1..6cdb6d6 100644 --- a/core/modules/comment/src/CommentLinkBuilder.php +++ b/core/modules/comment/src/CommentLinkBuilder.php @@ -66,14 +66,15 @@ public function __construct(AccountInterface $current_user, CommentManagerInterf /** * {@inheritdoc} */ - public function buildLinks(array &$entity_links, ContentEntityInterface $entity, array &$context) { + public function buildCommentedEntityLinks(ContentEntityInterface $entity, array &$context) { + $entity_links = array(); $view_mode = $context['view_mode']; if ($view_mode == 'search_index' || $view_mode == 'search_result' || $view_mode == 'print') { // Do not add any links if the entity is displayed for: // - search indexing. // - constructing a search result excerpt. // - print. - return; + return array(); } $fields = $this->commentManager->getFields($entity->getEntityTypeId()); @@ -216,6 +217,7 @@ public function buildLinks(array &$entity_links, ContentEntityInterface $entity, } } } + return $entity_links; } } diff --git a/core/modules/comment/src/CommentLinkBuilderInterface.php b/core/modules/comment/src/CommentLinkBuilderInterface.php index 8acb582..995efcf 100644 --- a/core/modules/comment/src/CommentLinkBuilderInterface.php +++ b/core/modules/comment/src/CommentLinkBuilderInterface.php @@ -19,13 +19,14 @@ /** * Builds links for the given entity. * - * @param array $entity_links - * Array of existing links keyed by link ID. * @param \Drupal\Core\Entity\ContentEntityInterface $entity * Entity for which the links are being built. * @param array $context * Array of context passed from the entity view builder. + * + * @return array + * Array of entity links. */ - public function buildLinks(array &$entity_links, ContentEntityInterface $entity, array &$context); + public function buildCommentedEntityLinks(ContentEntityInterface $entity, array &$context); } diff --git a/core/modules/comment/tests/src/CommentLinkBuilderTest.php b/core/modules/comment/tests/src/CommentLinkBuilderTest.php index 1c2e7c8..66ff397 100644 --- a/core/modules/comment/tests/src/CommentLinkBuilderTest.php +++ b/core/modules/comment/tests/src/CommentLinkBuilderTest.php @@ -83,7 +83,7 @@ public function setUp() { } /** - * Test the buildLinks method. + * Test the buildCommentedEntityLinks method. * * @param \Drupal\node\NodeInterface|\PHPUnit_Framework_MockObject_MockObject $node * Mock node. @@ -103,7 +103,7 @@ public function setUp() { * * @dataProvider getLinkCombinations * - * @covers ::buildLinks() + * @covers ::buildCommentedEntityLinks() */ public function testCommentLinkBuilder(NodeInterface $node, $context, $has_access_comments, $history_exists, $has_post_comments, $is_anonymous, $expected) { $this->moduleHandler->expects($this->any()) @@ -122,8 +122,7 @@ public function testCommentLinkBuilder(NodeInterface $node, $context, $has_acces $this->currentUser->expects($this->any()) ->method('isAnonymous') ->willReturn($is_anonymous); - $links = array(); - $this->commentLinkBuilder->buildLinks($links, $node, $context); + $links = $this->commentLinkBuilder->buildCommentedEntityLinks($node, $context); if (!empty($expected)) { if (!empty($links)) { foreach ($expected as $link => $detail) {