diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index 7c0a458..e8ae514 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -34,6 +34,16 @@ const TRANSLATION_CREATED = 2; /** + * Denotes that the entity is published. + */ + const STATUS_PUBLISHED = 1; + + /** + * Denotes that the entity is not published. + */ + const STATUS_UNPUBLISHED = 0; + + /** * The plain data values of the contained fields. * * This always holds the original, unchanged values of the entity. The values diff --git a/core/lib/Drupal/Core/Entity/EntityPublishedInterface.php b/core/lib/Drupal/Core/Entity/EntityPublishedInterface.php index 01dc312..56577e0 100644 --- a/core/lib/Drupal/Core/Entity/EntityPublishedInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityPublishedInterface.php @@ -5,16 +5,6 @@ interface EntityPublishedInterface { /** - * Denotes that the entity is published. - */ - const PUBLISHED = 1; - - /** - * Denotes that the entity is not published. - */ - const UNPUBLISHED = 0; - - /** * Returns the entity published status indicator. * * Unpublished entities are only visible to their authors and to administrators. diff --git a/core/modules/comment/src/CommentInterface.php b/core/modules/comment/src/CommentInterface.php index bda911c..78610ab 100644 --- a/core/modules/comment/src/CommentInterface.php +++ b/core/modules/comment/src/CommentInterface.php @@ -2,6 +2,7 @@ namespace Drupal\comment; +use Drupal\Core\Entity\ContentEntityBase; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityPublishedInterface; use Drupal\user\EntityOwnerInterface; @@ -15,12 +16,12 @@ /** * Comment is awaiting approval. */ - const NOT_PUBLISHED = 0; + const NOT_PUBLISHED = ContentEntityBase::STATUS_UNPUBLISHED; /** * Comment is published. */ - const PUBLISHED = 1; + const PUBLISHED = ContentEntityBase::STATUS_UNPUBLISHED; /** * Determines if this comment is a reply to another comment. @@ -193,6 +194,14 @@ public function getCreatedTime(); public function setCreatedTime($created); /** + * Checks if the comment is published. + * + * @return bool + * TRUE if the comment is published. + */ + public function isPublished(); + + /** * Returns the comment's status. * * @return int @@ -201,6 +210,17 @@ public function setCreatedTime($created); public function getStatus(); /** + * Sets the published status of the comment entity. + * + * @param bool $status + * Set to TRUE to publish the comment, FALSE to unpublish. + * + * @return \Drupal\comment\CommentInterface + * The class instance that this method is called on. + */ + public function setPublished($status); + + /** * Returns the alphadecimal representation of the comment's place in a thread. * * @return string diff --git a/core/modules/comment/src/Entity/Comment.php b/core/modules/comment/src/Entity/Comment.php index f3f1e4f..535d4de 100644 --- a/core/modules/comment/src/Entity/Comment.php +++ b/core/modules/comment/src/Entity/Comment.php @@ -7,7 +7,6 @@ use Drupal\Core\Entity\ContentEntityBase; use Drupal\comment\CommentInterface; use Drupal\Core\Entity\EntityChangedTrait; -use Drupal\Core\Entity\EntityPublishedInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\BaseFieldDefinition; @@ -80,7 +79,7 @@ public function preSave(EntityStorageInterface $storage) { parent::preSave($storage); if (is_null($this->get('status')->value)) { - $published = \Drupal::currentUser()->hasPermission('skip comment approval') ? CommentInterface::PUBLISHED : CommentInterface::NOT_PUBLISHED; + $published = \Drupal::currentUser()->hasPermission('skip comment approval') ? ContentEntityBase::STATUS_PUBLISHED : ContentEntityBase::STATUS_UNPUBLISHED; $this->setPublished($published); } if ($this->isNew()) { @@ -478,7 +477,7 @@ public function setCreatedTime($created) { * {@inheritdoc} */ public function isPublished() { - return $this->get('status')->value == EntityPublishedInterface::PUBLISHED; + return $this->get('status')->value == ContentEntityBase::PUBLISHED; } /** @@ -492,7 +491,7 @@ public function getStatus() { * {@inheritdoc} */ public function setPublished($status) { - $this->set('status', $status ? EntityPublishedInterface::PUBLISHED : EntityPublishedInterface::UNPUBLISHED); + $this->set('status', $status ? ContentEntityBase::PUBLISHED : ContentEntityBase::UNPUBLISHED); return $this; } diff --git a/core/modules/node/node.module b/core/modules/node/node.module index b151d7f..f9e2c4a 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -14,7 +14,7 @@ use Drupal\Core\Database\Query\AlterableInterface; use Drupal\Core\Database\Query\SelectInterface; use Drupal\Core\Database\StatementInterface; -use Drupal\Core\Entity\EntityPublishedInterface; +use Drupal\Core\Entity\ContentEntityBase; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; @@ -33,12 +33,12 @@ /** * Denotes that the node is not published. */ -const NODE_NOT_PUBLISHED = 0; +const NODE_NOT_PUBLISHED = ContentEntityBase::STATUS_UNPUBLISHED; /** * Denotes that the node is published. */ -const NODE_PUBLISHED = 1; +const NODE_PUBLISHED = ContentEntityBase::STATUS_PUBLISHED; /** * Denotes that the node is not promoted to the front page. @@ -742,15 +742,15 @@ function node_get_recent($number = 10) { // have some unpublished nodes to view before adding the condition. $access_query = \Drupal::entityQuery('node') ->condition('uid', $account->id()) - ->condition('status', NODE_NOT_PUBLISHED); + ->condition('status', ContentEntityBase::STATUS_UNPUBLISHED); if ($account->hasPermission('view own unpublished content') && ($own_unpublished = $access_query->execute())) { $query->orConditionGroup() - ->condition('status', NODE_PUBLISHED) + ->condition('status', ContentEntityBase::STATUS_UNPUBLISHED) ->condition('nid', $own_unpublished, 'IN'); } else { // If not, restrict the query to published nodes. - $query->condition('status', NODE_PUBLISHED); + $query->condition('status', ContentEntityBase::STATUS_PUBLISHED); } } $nids = $query diff --git a/core/modules/node/src/Entity/Node.php b/core/modules/node/src/Entity/Node.php index a113f5c..3c327c6 100644 --- a/core/modules/node/src/Entity/Node.php +++ b/core/modules/node/src/Entity/Node.php @@ -4,7 +4,6 @@ use Drupal\Core\Entity\ContentEntityBase; use Drupal\Core\Entity\EntityChangedTrait; -use Drupal\Core\Entity\EntityPublishedInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\BaseFieldDefinition; @@ -255,7 +254,7 @@ public function isPublished() { * {@inheritdoc} */ public function setPublished($published) { - $this->set('status', $published ? EntityPublishedInterface::PUBLISHED : EntityPublishedInterface::UNPUBLISHED); + $this->set('status', $published ? ContentEntityBase::PUBLISHED : ContentEntityBase::UNPUBLISHED); return $this; }