From 95019fa6167ec2485cc1cc728b58018ec0612a1c Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Tue, 12 Aug 2014 17:49:31 -0700 Subject: [PATCH] Issue #2318827 by larowlan, thehong | mgifford: Fixed Can't unpublish a comment. --- core/modules/comment/src/CommentForm.php | 2 +- core/modules/comment/src/CommentInterface.php | 8 ++++++++ core/modules/comment/src/Entity/Comment.php | 7 +++++++ core/modules/comment/src/Tests/CommentAdminTest.php | 2 ++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/core/modules/comment/src/CommentForm.php b/core/modules/comment/src/CommentForm.php index 7ea66537a4..3ba804d3d7 100644 --- a/core/modules/comment/src/CommentForm.php +++ b/core/modules/comment/src/CommentForm.php @@ -114,7 +114,7 @@ public function form(array $form, FormStateInterface $form_state) { // Prepare default values for form elements. if ($is_admin) { $author = $comment->getAuthorName(); - $status = $comment->isPublished(); + $status = $comment->getStatus(); if (empty($form_state['comment_preview'])) { $form['#title'] = $this->t('Edit comment %title', array( '%title' => $comment->getSubject(), diff --git a/core/modules/comment/src/CommentInterface.php b/core/modules/comment/src/CommentInterface.php index d2fd09af08..e7a4ee9485 100644 --- a/core/modules/comment/src/CommentInterface.php +++ b/core/modules/comment/src/CommentInterface.php @@ -212,6 +212,14 @@ public function getChangedTime(); */ public function isPublished(); + /** + * Returns the comment's status. + * + * @return int + * One of CommentInterface::PUBLISHED or CommentInterface::NOT_PUBLISHED + */ + public function getStatus(); + /** * Sets the published status of the comment entity. * diff --git a/core/modules/comment/src/Entity/Comment.php b/core/modules/comment/src/Entity/Comment.php index bb6c872291..8efdb4dad3 100644 --- a/core/modules/comment/src/Entity/Comment.php +++ b/core/modules/comment/src/Entity/Comment.php @@ -471,6 +471,13 @@ public function isPublished() { return $this->get('status')->value == CommentInterface::PUBLISHED; } + /** + * {@inheritdoc} + */ + public function getStatus() { + return $this->get('status')->value; + } + /** * {@inheritdoc} */ diff --git a/core/modules/comment/src/Tests/CommentAdminTest.php b/core/modules/comment/src/Tests/CommentAdminTest.php index 0ca8f2e2b8..811dfde8c0 100644 --- a/core/modules/comment/src/Tests/CommentAdminTest.php +++ b/core/modules/comment/src/Tests/CommentAdminTest.php @@ -136,6 +136,8 @@ function testApprovalNodeInterface() { $this->assertResponse(403, 'Forged comment approval was denied.'); $this->drupalGet('comment/1/approve', array('query' => array('token' => 'forged'))); $this->assertResponse(403, 'Forged comment approval was denied.'); + $this->drupalGet('comment/1/edit'); + $this->assertFieldChecked('edit-status-0'); $this->drupalGet('node/' . $this->node->id()); $this->clickLink(t('Approve')); $this->drupalLogout(); -- GitLab