Issue #3068563 by mikelutz, Berdir: Properly deprecate Comment::getStatus()
parent
0ea7ceec43
commit
4de7b7b46f
|
@ -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(),
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue