diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index e2c5675..7c0a458 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -1170,14 +1170,6 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setReadOnly(TRUE); } } - if ($entity_type->hasKey('status')) { - $fields[$entity_type->getKey('status')] = BaseFieldDefinition::create('boolean') - ->setLabel(new TranslatableMarkup('Publishing status')) - ->setDescription(t('A boolean indicating the published state.')) - ->setRevisionable(TRUE) - ->setTranslatable(TRUE) - ->setDefaultValue(TRUE); - } return $fields; } diff --git a/core/lib/Drupal/Core/Entity/EntityPublishedTrait.php b/core/lib/Drupal/Core/Entity/EntityPublishedTrait.php index e69de29..7f805b6 100644 --- a/core/lib/Drupal/Core/Entity/EntityPublishedTrait.php +++ b/core/lib/Drupal/Core/Entity/EntityPublishedTrait.php @@ -0,0 +1,34 @@ + BaseFieldDefinition::create('boolean') + ->setLabel(new TranslatableMarkup('Publishing status')) + ->setDescription(t('A boolean indicating the published state.')) + ->setRevisionable(TRUE) + ->setTranslatable(TRUE) + ->setDefaultValue(TRUE)]; + } + + /** + * {@inheritdoc} + */ + public function isPublished() { + return (bool) $this->get('status')->value; + } + + /** + * {@inheritdoc} + */ + public function setPublished($published) { + $this->set('status', $published ? NODE_PUBLISHED : NODE_NOT_PUBLISHED); + return $this; + } + +} diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install index ab761b6..38958aa 100644 --- a/core/modules/comment/comment.install +++ b/core/modules/comment/comment.install @@ -185,15 +185,10 @@ function comment_update_8200() { * @{ */ +/** + * Update status field. + */ function comment_update_8300() { - $lastInstalledSchemaRepository = \Drupal::service('entity.last_installed_schema.repository'); - /** @var \Drupal\Core\Entity\EntityTypeInterface $last_entity_type */ - $last_entity_type = $lastInstalledSchemaRepository->getLastInstalledDefinition('comment'); - $keys = $last_entity_type->getKeys(); - $keys['status'] = 'status'; - $last_entity_type->set('entity_keys', $keys); - $lastInstalledSchemaRepository->setLastInstalledDefinition($last_entity_type); - $field_definitions = \Drupal::service('entity_field.manager')->getBaseFieldDefinitions('comment'); \Drupal::service('entity.definition_update_manager')->updateFieldStorageDefinition($field_definitions['status']); } diff --git a/core/modules/comment/src/Entity/Comment.php b/core/modules/comment/src/Entity/Comment.php index 97cefeb..e394a83 100644 --- a/core/modules/comment/src/Entity/Comment.php +++ b/core/modules/comment/src/Entity/Comment.php @@ -7,6 +7,7 @@ use Drupal\Core\Entity\ContentEntityBase; use Drupal\comment\CommentInterface; use Drupal\Core\Entity\EntityChangedTrait; +use Drupal\Core\Entity\EntityPublishedTrait; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\BaseFieldDefinition; @@ -50,7 +51,6 @@ * "label" = "subject", * "langcode" = "langcode", * "uuid" = "uuid", - * "status" = "status" * }, * links = { * "canonical" = "/comment/{comment}", @@ -67,6 +67,7 @@ class Comment extends ContentEntityBase implements CommentInterface { use EntityChangedTrait; + use EntityPublishedTrait; /** * The thread for which a lock was acquired. @@ -217,6 +218,7 @@ public function permalink() { public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { /** @var \Drupal\Core\Field\BaseFieldDefinition[] $fields */ $fields = parent::baseFieldDefinitions($entity_type); + $fields += static::publishedBaseFieldDefinitions($entity_type); $fields['cid']->setLabel(t('Comment ID')) ->setDescription(t('The comment ID.')); @@ -471,13 +473,6 @@ public function setCreatedTime($created) { /** * {@inheritdoc} */ - public function isPublished() { - return $this->get('status')->value == CommentInterface::PUBLISHED; - } - - /** - * {@inheritdoc} - */ public function getStatus() { return $this->get('status')->value; } @@ -485,14 +480,6 @@ public function getStatus() { /** * {@inheritdoc} */ - public function setPublished($status) { - $this->set('status', $status ? CommentInterface::PUBLISHED : CommentInterface::NOT_PUBLISHED); - return $this; - } - - /** - * {@inheritdoc} - */ public function getThread() { $thread = $this->get('thread'); if (!empty($thread->value)) { diff --git a/core/modules/node/src/Entity/Node.php b/core/modules/node/src/Entity/Node.php index e4c123e..3863388 100644 --- a/core/modules/node/src/Entity/Node.php +++ b/core/modules/node/src/Entity/Node.php @@ -4,6 +4,7 @@ use Drupal\Core\Entity\ContentEntityBase; use Drupal\Core\Entity\EntityChangedTrait; +use Drupal\Core\Entity\EntityPublishedTrait; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\BaseFieldDefinition; @@ -54,7 +55,6 @@ * "label" = "title", * "langcode" = "langcode", * "uuid" = "uuid", - * "status" = "status", * "uid" = "uid", * }, * bundle_entity_type = "node_type", @@ -73,6 +73,7 @@ class Node extends ContentEntityBase implements NodeInterface { use EntityChangedTrait; + use EntityPublishedTrait; /** * Whether the node is being previewed or not. @@ -242,20 +243,6 @@ public function setSticky($sticky) { $this->set('sticky', $sticky ? NODE_STICKY : NODE_NOT_STICKY); return $this; } - /** - * {@inheritdoc} - */ - public function isPublished() { - return (bool) $this->getEntityKey('status'); - } - - /** - * {@inheritdoc} - */ - public function setPublished($published) { - $this->set('status', $published ? NODE_PUBLISHED : NODE_NOT_PUBLISHED); - return $this; - } /** * {@inheritdoc} @@ -367,6 +354,7 @@ public function setRevisionLogMessage($revision_log_message) { */ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields = parent::baseFieldDefinitions($entity_type); + $fields += static::publishedBaseFieldDefinitions($entity_type); $fields['title'] = BaseFieldDefinition::create('string') ->setLabel(t('Title'))