diff --git a/core/modules/comment/src/CommentLinkBuilder.php b/core/modules/comment/src/CommentLinkBuilder.php index 7ce175c..8d43f2f 100644 --- a/core/modules/comment/src/CommentLinkBuilder.php +++ b/core/modules/comment/src/CommentLinkBuilder.php @@ -208,7 +208,7 @@ public function buildCommentedEntityLinks(FieldableEntityInterface $entity, arra if ($new_comments > 0) { $page_number = $this->entityManager ->getStorage('comment') - ->getNewCommentPageNumber($entity->{$field_name}->comment_count, $new_comments, $entity); + ->getNewCommentPageNumber($entity->{$field_name}->comment_count, $new_comments, $entity, $field_name); $query = $page_number ? ['page' => $page_number] : NULL; $value = [ 'new_comment_count' => (int) $new_comments, diff --git a/core/modules/comment/src/Tests/CommentFieldsTest.php b/core/modules/comment/src/Tests/CommentFieldsTest.php index 77cbbc0..ccfea18 100644 --- a/core/modules/comment/src/Tests/CommentFieldsTest.php +++ b/core/modules/comment/src/Tests/CommentFieldsTest.php @@ -95,6 +95,27 @@ public function testCommentFieldDelete() { } /** + * Tests link building with non-default comment field names. + */ + public function testCommentFieldLinksNonDefaultName() { + $this->drupalCreateContentType(array('type' => 'test_node_type')); + $this->addDefaultCommentField('node', 'test_node_type', 'comment2'); + + // Create a sample node. + $node = $this->drupalCreateNode(array( + 'title' => 'Baloney', + 'type' => 'test_node_type', + )); + + // Test that buildCommentedEntityLinks() does not break when the 'comment' + // field does not exist. Requires at least one comment. + $this->drupalLogin($this->webUser); + $this->postComment($node, 'Here is a comment', '', NULL, 'comment2'); + $context = ['view_mode' => 'teaser']; + \Drupal::service('comment.link_builder')->buildCommentedEntityLinks($node, $context); + } + + /** * Tests creating a comment field through the interface. */ public function testCommentFieldCreate() {