diff --git a/core/modules/comment/src/Controller/CommentController.php b/core/modules/comment/src/Controller/CommentController.php index be8219a..7a385be 100644 --- a/core/modules/comment/src/Controller/CommentController.php +++ b/core/modules/comment/src/Controller/CommentController.php @@ -207,11 +207,6 @@ public function redirectNode(EntityInterface $node) { * - comment_entity: If the comment is a reply to the entity. * - comment_parent: If the comment is a reply to another comment. * - comment_form: The comment form as a renderable array. - * - An associative array containing: - * - An array for rendering the entity or parent comment. - * - comment_entity: If the comment is a reply to the entity. - * - comment_parent: If the comment is a reply to another comment. - * - comment_form: The comment form as a renderable array. * - A redirect response to current node: * - If user is not authorized to post comments. * - If parent comment doesn't belong to current entity. diff --git a/core/modules/comment/src/Entity/Comment.php b/core/modules/comment/src/Entity/Comment.php index 909abc3..99a719a 100644 --- a/core/modules/comment/src/Entity/Comment.php +++ b/core/modules/comment/src/Entity/Comment.php @@ -119,6 +119,12 @@ public function preSave(EntityStorageInterface $storage) { $parent_depth = count(explode('.', $parent->getThread())); $n = Number::alphadecimalToInt($parts[$parent_depth]); } + + // If the parent is not published, this comment should be published as + // well. + if(!$parent->isPublished()) { + $this->setPublished(FALSE); + } } // Finally, build the thread field for this new comment. To avoid // race conditions, get a lock on the thread. If another process already diff --git a/core/modules/comment/src/Tests/CommentInterfaceTest.php b/core/modules/comment/src/Tests/CommentInterfaceTest.php index 6cb5df6..92822c2 100644 --- a/core/modules/comment/src/Tests/CommentInterfaceTest.php +++ b/core/modules/comment/src/Tests/CommentInterfaceTest.php @@ -162,9 +162,12 @@ public function testCommentInterface() { $this->assertNoText(t('The comment you are replying to does not exist.'), 'Replying to an unpublished comment as an administration user.'); $reply = $this->postComment(NULL, $this->randomMachineName(), $this->randomMachineName(), TRUE); $this->assertTrue($this->commentExists($reply, TRUE), 'An administration user was able to comment to an unpublished comment.'); + // Make sure the reply on the unpublished comment is unpublished as well. + $this->drupalLogin($this->webUser); + $this->drupalGet('node/' . $this->node->getOriginalId()); + $this->assertFalse($this->commentExists($reply), 'The unpublished reply was not found.'); // Attempt to post to node with comments disabled. - $this->drupalLogin($this->webUser); $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'comment' => array(array('status' => CommentItemInterface::HIDDEN)))); $this->assertTrue($this->node, 'Article node created.'); $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment');