Issue #3068563 by mikelutz, Berdir: Properly deprecate Comment::getStatus()

merge-requests/55/head
Alex Pott 2019-07-23 11:27:12 +01:00
parent 0ea7ceec43
commit 4de7b7b46f
No known key found for this signature in database
GPG Key ID: 31905460D4A69276
6 changed files with 25 additions and 7 deletions

View File

@ -141,7 +141,7 @@ class CommentForm extends ContentEntityForm {
if (!$comment->getOwnerId()) {
$author = $comment->getAuthorName();
}
$status = $comment->getStatus();
$status = $comment->isPublished() ? CommentInterface::PUBLISHED : CommentInterface::NOT_PUBLISHED;
if (empty($comment_preview)) {
$form['#title'] = $this->t('Edit comment %title', [
'%title' => $comment->getSubject(),

View File

@ -211,11 +211,14 @@ interface CommentInterface extends ContentEntityInterface, EntityChangedInterfac
/**
* Returns the comment's status.
*
* @return int
* One of CommentInterface::PUBLISHED or CommentInterface::NOT_PUBLISHED
* @return int|string|bool
* Either TRUE, '1', or CommentInterface::PUBLISHED(1) if the comment is
* published, or FALSE, '0', or CommentInterface::NOT_PUBLISHED(0) if the
* comment is not published.
*
* @deprecated in Drupal 8.3.0, will be removed before Drupal 9.0.0. Use
* @deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Use
* \Drupal\Core\Entity\EntityPublishedInterface::isPublished() instead.
* @see https://www.drupal.org/node/2830201
*/
public function getStatus();

View File

@ -490,6 +490,7 @@ class Comment extends ContentEntityBase implements CommentInterface {
* {@inheritdoc}
*/
public function getStatus() {
@trigger_error(__NAMESPACE__ . '\Comment::getStatus() is deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Entity\EntityPublishedInterface::isPublished() instead. See https://www.drupal.org/node/2830201', E_USER_DEPRECATED);
return $this->get('status')->value;
}

View File

@ -347,7 +347,7 @@ abstract class CommentResourceTestBase extends EntityResourceTestBase {
$response = $this->request('POST', $url, $request_options);
$unserialized = $this->serializer->deserialize((string) $response->getBody(), get_class($this->entity), static::$format);
$this->assertResourceResponse(201, FALSE, $response);
$this->assertFalse($unserialized->getStatus());
$this->assertFalse($unserialized->isPublished());
// Grant anonymous permission to skip comment approval.
$this->grantPermissionsToTestedRole(['skip comment approval']);
@ -356,7 +356,7 @@ abstract class CommentResourceTestBase extends EntityResourceTestBase {
$response = $this->request('POST', $url, $request_options);
$unserialized = $this->serializer->deserialize((string) $response->getBody(), get_class($this->entity), static::$format);
$this->assertResourceResponse(201, FALSE, $response);
$this->assertTrue($unserialized->getStatus());
$this->assertTrue($unserialized->isPublished());
}
/**

View File

@ -2,6 +2,7 @@
namespace Drupal\Tests\comment\Kernel;
use Drupal\comment\CommentInterface;
use Drupal\comment\Entity\Comment;
use Drupal\comment\Entity\CommentType;
use Drupal\entity_test\Entity\EntityTest;
@ -90,4 +91,17 @@ class CommentLegacyTest extends EntityKernelTestBase {
$this->assertEquals(4, count(comment_view_multiple($entities)));
}
/**
* Tests the getStatus() method.
*
* @expectedDeprecation Drupal\comment\Entity\Comment::getStatus() is deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Entity\EntityPublishedInterface::isPublished() instead. See https://www.drupal.org/node/2830201
*/
public function testGetStatus() {
$entity = $this->createComment();
$entity->setPublished();
$this->assertEquals(CommentInterface::PUBLISHED, $entity->getStatus());
$entity->setUnPublished();
$this->assertEquals(CommentInterface::NOT_PUBLISHED, $entity->getStatus());
}
}

View File

@ -71,7 +71,7 @@ class MigrateCommentTest extends MigrateDrupal7TestBase {
$this->assertSame('Subject field in English', $comment->getSubject());
$this->assertSame('1421727536', $comment->getCreatedTime());
$this->assertSame('1421727536', $comment->getChangedTime());
$this->assertTrue($comment->getStatus());
$this->assertTrue($comment->isPublished());
$this->assertSame('admin', $comment->getAuthorName());
$this->assertSame('admin@local.host', $comment->getAuthorEmail());
$this->assertSame('This is a comment', $comment->comment_body->value);