diff --git a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php index c701de3..e77d74a 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php @@ -169,9 +169,9 @@ public function __construct(EntityTypeInterface $entity_type, Connection $databa */ protected function initTableLayout() { $this->idKey = $this->entityType->getKey('id') ?: 'id'; - $this->uuidKey = $this->entityType->getKey('uuid') ?: 'uuid'; - // The bundle key is optional. + // The uuid and bundle keys are optional. + $this->uuidKey = $this->entityType->getKey('uuid'); $this->bundleKey = $this->entityType->getKey('bundle'); // @todo Remove table names from the entity type definition in @@ -757,72 +757,72 @@ public function save(EntityInterface $entity) { * {@inheritdoc} */ protected function doSave($id, EntityInterface $entity) { - // Create the storage record to be saved. - $record = $this->mapToStorageRecord($entity); + // Create the storage record to be saved. + $record = $this->mapToStorageRecord($entity); $is_new = $entity->isNew(); if (!$is_new) { - if ($entity->isDefaultRevision()) { - $this->database - ->update($this->baseTable) - ->fields((array) $record) - ->condition($this->idKey, $record->{$this->idKey}) - ->execute(); - $return = SAVED_UPDATED; - } - else { - // @todo, should a different value be returned when saving an entity - // with $isDefaultRevision = FALSE? - $return = FALSE; - } - if ($this->revisionTable) { - $entity->{$this->revisionKey}->value = $this->saveRevision($entity); - } - if ($this->dataTable) { - $this->savePropertyData($entity); - } - if ($this->revisionDataTable) { - $this->savePropertyData($entity, $this->revisionDataTable); - } - if ($this->revisionTable) { - $entity->setNewRevision(FALSE); - } - $cache_ids = array($entity->id()); - } - else { - // Ensure the entity is still seen as new after assigning it an id, - // while storing its data. - $entity->enforceIsNew(); - $insert_id = $this->database - ->insert($this->baseTable, array('return' => Database::RETURN_INSERT_ID)) + if ($entity->isDefaultRevision()) { + $this->database + ->update($this->baseTable) ->fields((array) $record) + ->condition($this->idKey, $record->{$this->idKey}) ->execute(); - // Even if this is a new entity the ID key might have been set, in which - // case we should not override the provided ID. An empty value for the - // id is interpreted as NULL and thus overriden. - if (empty($record->{$this->idKey})) { - $record->{$this->idKey} = $insert_id; - } - $return = SAVED_NEW; - $entity->{$this->idKey}->value = (string) $record->{$this->idKey}; - if ($this->revisionTable) { - $entity->setNewRevision(); - $record->{$this->revisionKey} = $this->saveRevision($entity); - } - if ($this->dataTable) { - $this->savePropertyData($entity); - } - if ($this->revisionDataTable) { - $this->savePropertyData($entity, $this->revisionDataTable); - } + $return = SAVED_UPDATED; + } + else { + // @todo, should a different value be returned when saving an entity + // with $isDefaultRevision = FALSE? + $return = FALSE; + } + if ($this->revisionTable) { + $entity->{$this->revisionKey}->value = $this->saveRevision($entity); + } + if ($this->dataTable) { + $this->savePropertyData($entity); + } + if ($this->revisionDataTable) { + $this->savePropertyData($entity, $this->revisionDataTable); + } + if ($this->revisionTable) { + $entity->setNewRevision(FALSE); + } + $cache_ids = array($entity->id()); + } + else { + // Ensure the entity is still seen as new after assigning it an id, + // while storing its data. + $entity->enforceIsNew(); + $insert_id = $this->database + ->insert($this->baseTable, array('return' => Database::RETURN_INSERT_ID)) + ->fields((array) $record) + ->execute(); + // Even if this is a new entity the ID key might have been set, in which + // case we should not override the provided ID. An empty value for the + // id is interpreted as NULL and thus overriden. + if (empty($record->{$this->idKey})) { + $record->{$this->idKey} = $insert_id; + } + $return = SAVED_NEW; + $entity->{$this->idKey}->value = (string) $record->{$this->idKey}; + if ($this->revisionTable) { + $entity->setNewRevision(); + $record->{$this->revisionKey} = $this->saveRevision($entity); + } + if ($this->dataTable) { + $this->savePropertyData($entity); + } + if ($this->revisionDataTable) { + $this->savePropertyData($entity, $this->revisionDataTable); + } - $entity->enforceIsNew(FALSE); - if ($this->revisionTable) { - $entity->setNewRevision(FALSE); - } - // Reset general caches, but keep caches specific to certain entities. - $cache_ids = array(); + $entity->enforceIsNew(FALSE); + if ($this->revisionTable) { + $entity->setNewRevision(FALSE); } + // Reset general caches, but keep caches specific to certain entities. + $cache_ids = array(); + } $this->invokeFieldMethod($is_new ? 'insert' : 'update', $entity); $this->saveFieldItems($entity, !$is_new); $this->resetCache($cache_ids); @@ -830,8 +830,8 @@ protected function doSave($id, EntityInterface $entity) { if (!$is_new && $this->dataTable) { $this->invokeTranslationHooks($entity); } - return $return; - } + return $return; + } /** * {@inheritdoc}