diff --git a/core/lib/Drupal/Core/Entity/EntityPublishedTrait.php b/core/lib/Drupal/Core/Entity/EntityPublishedTrait.php index 7f805b6..8871dba 100644 --- a/core/lib/Drupal/Core/Entity/EntityPublishedTrait.php +++ b/core/lib/Drupal/Core/Entity/EntityPublishedTrait.php @@ -8,7 +8,8 @@ trait EntityPublishedTrait { public static function publishedBaseFieldDefinitions(EntityTypeInterface $entity_type) { - return ['status' => BaseFieldDefinition::create('boolean') + $key = $entity_type->hasKey('status') ? $entity_type->getKey('status') : 'status'; + return [$key => BaseFieldDefinition::create('boolean') ->setLabel(new TranslatableMarkup('Publishing status')) ->setDescription(t('A boolean indicating the published state.')) ->setRevisionable(TRUE) @@ -20,14 +21,21 @@ public static function publishedBaseFieldDefinitions(EntityTypeInterface $entity * {@inheritdoc} */ public function isPublished() { - return (bool) $this->get('status')->value; + return $this->getEntityType()->hasKey('status') ? + (bool) $this->getEntityKey('status') : + (bool) $this->get('status')->value; } /** * {@inheritdoc} */ public function setPublished($published) { - $this->set('status', $published ? NODE_PUBLISHED : NODE_NOT_PUBLISHED); + /** @var \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type */ + $entity_type = $this->getEntityType(); + $key = $entity_type->hasKey('status') ? $entity_type->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/modules/node/src/Entity/Node.php b/core/modules/node/src/Entity/Node.php index f5470ef..d4e4715 100644 --- a/core/modules/node/src/Entity/Node.php +++ b/core/modules/node/src/Entity/Node.php @@ -55,7 +55,8 @@ * "label" = "title", * "langcode" = "langcode", * "uuid" = "uuid", - * "uid" = "uid" + * "status" = "status", + * "uid" = "uid", * }, * bundle_entity_type = "node_type", * field_ui_base_route = "entity.node_type.edit_form", diff --git a/core/modules/rest/src/Tests/UpdateTest.php b/core/modules/rest/src/Tests/UpdateTest.php index 4fb84b0..287c2df 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',