diff --git a/core/lib/Drupal/Core/Entity/EntityPublishedInterface.php b/core/lib/Drupal/Core/Entity/EntityPublishedInterface.php deleted file mode 100644 index 4372008c19cd963eb7cac72c7f945ef2738fdbb6..0000000000000000000000000000000000000000 --- a/core/lib/Drupal/Core/Entity/EntityPublishedInterface.php +++ /dev/null @@ -1,41 +0,0 @@ -<?php - -namespace Drupal\Core\Entity; - -/** - * Provides an interface for access to an entity's published state. - */ -interface EntityPublishedInterface { - - /** - * Returns whether or not the entity is published. - * - * @return bool - * TRUE if the entity is published, FALSE otherwise. - */ - public function isPublished(); - - /** - * Sets the entity as published. - * - * @param bool|null $published - * (optional and deprecated) TRUE to set this entity to published, FALSE to - * set it to unpublished. Defaults to NULL. This parameter is deprecated in - * Drupal 8.3.0 and will be removed before Drupal 9.0.0. Use this method, - * without any parameter, to set the entity as published and - * setUnpublished() to set the entity as unpublished. - * - * @return $this - * - * @see \Drupal\Core\Entity\EntityPublishedInterface::setUnpublished() - */ - public function setPublished($published = NULL); - - /** - * Sets the entity as unpublished. - * - * @return $this - */ - public function setUnpublished(); - -} diff --git a/core/lib/Drupal/Core/Entity/EntityPublishedTrait.php b/core/lib/Drupal/Core/Entity/EntityPublishedTrait.php index 871aceb365c333501a5e68725325293c5c4e7096..2145f4a61e8a8c61f459ef7e3acf0764b519b476 100644 --- a/core/lib/Drupal/Core/Entity/EntityPublishedTrait.php +++ b/core/lib/Drupal/Core/Entity/EntityPublishedTrait.php @@ -2,7 +2,6 @@ namespace Drupal\Core\Entity; -use Drupal\Core\Entity\Exception\UnsupportedEntityTypeDefinitionException; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\StringTranslation\TranslatableMarkup; @@ -18,21 +17,11 @@ trait EntityPublishedTrait { * The entity type to add the publishing status field to. * * @return \Drupal\Core\Field\BaseFieldDefinition[] - * An array of base field definitions. - * - * @throws \Drupal\Core\Entity\Exception\UnsupportedEntityTypeDefinitionException - * Thrown when the entity type does not implement EntityPublishedInterface - * or if it does not have a "published" entity key. + * Array of base field definitions. */ public static function publishedBaseFieldDefinitions(EntityTypeInterface $entity_type) { - if (!is_subclass_of($entity_type->getClass(), EntityPublishedInterface::class)) { - throw new UnsupportedEntityTypeDefinitionException('The entity type ' . $entity_type->id() . ' does not implement \Drupal\Core\Entity\EntityPublishedInterface.'); - } - if (!$entity_type->hasKey('published')) { - throw new UnsupportedEntityTypeDefinitionException('The entity type ' . $entity_type->id() . ' does not have a "published" entity key.'); - } - - return [$entity_type->getKey('published') => BaseFieldDefinition::create('boolean') + $key = $entity_type->hasKey('status') ? $entity_type->getKey('status') : 'status'; + return [$key => BaseFieldDefinition::create('boolean') ->setLabel(new TranslatableMarkup('Publishing status')) ->setDescription(new TranslatableMarkup('A boolean indicating the published state.')) ->setRevisionable(TRUE) @@ -41,37 +30,31 @@ public static function publishedBaseFieldDefinitions(EntityTypeInterface $entity } /** - * {@inheritdoc} + * Returns the published status of the entity. + * + * @return bool + * The published status of the entity. */ public function isPublished() { - $key = $this->getEntityType()->getKey('published'); - return (bool) $this->get($key)->value; - } - - /** - * {@inheritdoc} - */ - public function setPublished($published = NULL) { - if ($published !== NULL) { - @trigger_error('The $published parameter is deprecated since version 8.3.x and will be removed in 9.0.0.', E_USER_DEPRECATED); - $value = (bool) $published; - } - else { - $value = TRUE; - } - $key = $this->getEntityType()->getKey('published'); - $this->set($key, $value); - - return $this; + $status = $this->getEntityKey('status'); + return (bool) (isset($status) ? $status : $this->get('status')->value); } /** - * {@inheritdoc} + * Sets the entity as published or not published. + * + * @param bool $published + * A boolean value denoting the published status. + * + * @return \Drupal\Core\Entity\ContentEntityInterface $this + * The Content Entity object. */ - public function setUnpublished() { - $key = $this->getEntityType()->getKey('published'); - $this->set($key, FALSE); - + public function setPublished($published) { + /** @var \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type */ + $key = $this->getEntityType()->getKey('status') ?: 'status'; + // @todo: Replace values with constants from EntityPublishedInterface or + // similar when introduced. https://www.drupal.org/node/2811667 + $this->set($key, $published ? 1 : 0); return $this; } diff --git a/core/lib/Drupal/Core/Entity/Exception/UnsupportedEntityTypeDefinitionException.php b/core/lib/Drupal/Core/Entity/Exception/UnsupportedEntityTypeDefinitionException.php deleted file mode 100644 index 079b42215a8563e8ce5c6324c1c4cb790ac7f175..0000000000000000000000000000000000000000 --- a/core/lib/Drupal/Core/Entity/Exception/UnsupportedEntityTypeDefinitionException.php +++ /dev/null @@ -1,8 +0,0 @@ -<?php - -namespace Drupal\Core\Entity\Exception; - -/** - * Defines an exception thrown when an entity type definition is invalid. - */ -class UnsupportedEntityTypeDefinitionException extends \Exception { } diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install index 895c0397ab67bd46670c9edf1e18a680cf63c6c9..38958aa78801c5575f9f2611b49cdfd5dd8b5b7a 100644 --- a/core/modules/comment/comment.install +++ b/core/modules/comment/comment.install @@ -193,18 +193,6 @@ function comment_update_8300() { \Drupal::service('entity.definition_update_manager')->updateFieldStorageDefinition($field_definitions['status']); } -/** - * Set the 'published' entity key. - */ -function comment_update_8301() { - $definition_update_manager = \Drupal::entityDefinitionUpdateManager(); - $entity_type = $definition_update_manager->getEntityType('comment'); - $keys = $entity_type->getKeys(); - $keys['published'] = 'status'; - $entity_type->set('entity_keys', $keys); - $definition_update_manager->updateEntityType($entity_type); -} - /** * @} End of "addtogroup updates-8.3.x". */ diff --git a/core/modules/comment/src/CommentInterface.php b/core/modules/comment/src/CommentInterface.php index 9f3360c1ed344211f77f9e7e575f9ff6a8b02352..28318eea1530ea1767df1632ad967d705fcc833e 100644 --- a/core/modules/comment/src/CommentInterface.php +++ b/core/modules/comment/src/CommentInterface.php @@ -3,14 +3,13 @@ namespace Drupal\comment; use Drupal\Core\Entity\ContentEntityInterface; -use Drupal\Core\Entity\EntityPublishedInterface; use Drupal\user\EntityOwnerInterface; use Drupal\Core\Entity\EntityChangedInterface; /** * Provides an interface defining a comment entity. */ -interface CommentInterface extends ContentEntityInterface, EntityChangedInterface, EntityOwnerInterface, EntityPublishedInterface { +interface CommentInterface extends ContentEntityInterface, EntityChangedInterface, EntityOwnerInterface { /** * Comment is awaiting approval. @@ -192,17 +191,33 @@ 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 * One of CommentInterface::PUBLISHED or CommentInterface::NOT_PUBLISHED - * - * @deprecated in Drupal 8.3.0, will be removed before Drupal 9.0.0. Use - * \Drupal\Core\Entity\EntityPublishedInterface::isPublished() instead. */ 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. * diff --git a/core/modules/comment/src/Entity/Comment.php b/core/modules/comment/src/Entity/Comment.php index d52f04dcbb9a0655cf6e005b894c0e1c5019f94e..a244163c59fbbd9d46d01aafc2e218e30afc4234 100644 --- a/core/modules/comment/src/Entity/Comment.php +++ b/core/modules/comment/src/Entity/Comment.php @@ -50,8 +50,7 @@ * "bundle" = "comment_type", * "label" = "subject", * "langcode" = "langcode", - * "uuid" = "uuid", - * "published" = "status", + * "uuid" = "uuid" * }, * links = { * "canonical" = "/comment/{comment}", @@ -82,12 +81,8 @@ public function preSave(EntityStorageInterface $storage) { parent::preSave($storage); if (is_null($this->get('status')->value)) { - if (\Drupal::currentUser()->hasPermission('skip comment approval')) { - $this->setPublished(); - } - else { - $this->setUnpublished(); - } + $published = \Drupal::currentUser()->hasPermission('skip comment approval') ? CommentInterface::PUBLISHED : CommentInterface::NOT_PUBLISHED; + $this->setPublished($published); } if ($this->isNew()) { // Add the comment to database. This next section builds the thread field. diff --git a/core/modules/comment/src/Tests/Update/CommentUpdateTest.php b/core/modules/comment/src/Tests/Update/CommentUpdateTest.php index 1bf3bdc340931659c8d4c3db534eea6c14455bc8..61d187d509cc5260e04330a88fe06211b7a802ea 100644 --- a/core/modules/comment/src/Tests/Update/CommentUpdateTest.php +++ b/core/modules/comment/src/Tests/Update/CommentUpdateTest.php @@ -50,22 +50,4 @@ public function testCommentUpdate8101() { $this->assertIdentical($config->get('content.comment_forum.settings.view_mode'), 'default'); } - /** - * Tests that the comment entity type has a 'published' entity key. - * - * @see comment_update_8301() - */ - public function testPublishedEntityKey() { - // Check that the 'published' entity key does not exist prior to the update. - $entity_type = \Drupal::entityDefinitionUpdateManager()->getEntityType('comment'); - $this->assertFalse($entity_type->getKey('published')); - - // Run updates. - $this->runUpdates(); - - // Check that the entity key exists and it has the correct value. - $entity_type = \Drupal::entityDefinitionUpdateManager()->getEntityType('comment'); - $this->assertEqual('status', $entity_type->getKey('published')); - } - } diff --git a/core/modules/node/node.install b/core/modules/node/node.install index 2751b2c14d1891c68df82c95522a2db3f83653f9..720a7e0398280a7cf20e8d0172589e12d336c712 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -221,11 +221,6 @@ function node_update_8003() { } } -/** - * @addtogroup updates-8.3.x - * @{ - */ - /** * Change {node_access}.fallback from an int to a tinyint as it is a boolean. */ @@ -239,19 +234,3 @@ function node_update_8300() { 'size' => 'tiny', ]); } - -/** - * Set the 'published' entity key. - */ -function node_update_8301() { - $definition_update_manager = \Drupal::entityDefinitionUpdateManager(); - $entity_type = $definition_update_manager->getEntityType('node'); - $keys = $entity_type->getKeys(); - $keys['published'] = 'status'; - $entity_type->set('entity_keys', $keys); - $definition_update_manager->updateEntityType($entity_type); -} - -/** - * @} End of "addtogroup updates-8.3.x". - */ diff --git a/core/modules/node/src/Entity/Node.php b/core/modules/node/src/Entity/Node.php index f034957988eeda47418e231ded355d7d38fcdfef..d4e47155e22a0575f15b085ee7777cc4f86cd215 100644 --- a/core/modules/node/src/Entity/Node.php +++ b/core/modules/node/src/Entity/Node.php @@ -56,7 +56,6 @@ * "langcode" = "langcode", * "uuid" = "uuid", * "status" = "status", - * "published" = "status", * "uid" = "uid", * }, * bundle_entity_type = "node_type", diff --git a/core/modules/node/src/NodeInterface.php b/core/modules/node/src/NodeInterface.php index f3bcaeada027913199f2ee03f83964d6d27b21fb..980dacd06fa51d87945cccb983e2c3a3dfbeb799 100644 --- a/core/modules/node/src/NodeInterface.php +++ b/core/modules/node/src/NodeInterface.php @@ -2,7 +2,6 @@ namespace Drupal\node; -use Drupal\Core\Entity\EntityPublishedInterface; use Drupal\Core\Entity\RevisionLogInterface; use Drupal\user\EntityOwnerInterface; use Drupal\Core\Entity\EntityChangedInterface; @@ -11,7 +10,7 @@ /** * Provides an interface defining a node entity. */ -interface NodeInterface extends ContentEntityInterface, EntityChangedInterface, EntityOwnerInterface, RevisionLogInterface, EntityPublishedInterface { +interface NodeInterface extends ContentEntityInterface, EntityChangedInterface, EntityOwnerInterface, RevisionLogInterface { /** * Gets the node type. @@ -97,6 +96,27 @@ public function isSticky(); */ public function setSticky($sticky); + /** + * Returns the node published status indicator. + * + * Unpublished nodes are only visible to their authors and to administrators. + * + * @return bool + * TRUE if the node is published. + */ + public function isPublished(); + + /** + * Sets the published status of a node.. + * + * @param bool $published + * TRUE to set this node to published, FALSE to set it to unpublished. + * + * @return \Drupal\node\NodeInterface + * The called node entity. + */ + public function setPublished($published); + /** * Gets the node revision creation timestamp. * diff --git a/core/modules/node/src/Tests/Update/NodeUpdateTest.php b/core/modules/node/src/Tests/Update/NodeUpdateTest.php deleted file mode 100644 index b8b30be4f1e786c350200ed7e16f09c371a1af27..0000000000000000000000000000000000000000 --- a/core/modules/node/src/Tests/Update/NodeUpdateTest.php +++ /dev/null @@ -1,41 +0,0 @@ -<?php - -namespace Drupal\node\Tests\Update; - -use Drupal\system\Tests\Update\UpdatePathTestBase; - -/** - * Tests that node settings are properly updated during database updates. - * - * @group node - */ -class NodeUpdateTest extends UpdatePathTestBase { - - /** - * {@inheritdoc} - */ - protected function setDatabaseDumpFiles() { - $this->databaseDumpFiles = [ - __DIR__ . '/../../../../system/tests/fixtures/update/drupal-8-rc1.bare.standard.php.gz', - ]; - } - - /** - * Tests that the node entity type has a 'published' entity key. - * - * @see node_update_8301() - */ - public function testPublishedEntityKey() { - // Check that the 'published' entity key does not exist prior to the update. - $entity_type = \Drupal::entityDefinitionUpdateManager()->getEntityType('node'); - $this->assertFalse($entity_type->getKey('published')); - - // Run updates. - $this->runUpdates(); - - // Check that the entity key exists and it has the correct value. - $entity_type = \Drupal::entityDefinitionUpdateManager()->getEntityType('node'); - $this->assertEqual('status', $entity_type->getKey('published')); - } - -} diff --git a/core/modules/rest/src/Tests/UpdateTest.php b/core/modules/rest/src/Tests/UpdateTest.php index 4fb84b0f4904858133b0169be7853d14586f910b..287c2df089eda04178856ad00fdb7ba66d9733a0 100644 --- a/core/modules/rest/src/Tests/UpdateTest.php +++ b/core/modules/rest/src/Tests/UpdateTest.php @@ -311,6 +311,7 @@ public function testUpdateComment() { $this->pass('Test case 1: PATCH comment using JSON.'); $comment->setSubject('Initial subject')->save(); $read_only_fields = [ + 'status', 'pid', // Extra compared to HAL+JSON. 'entity_id', 'uid',