diff --git a/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php b/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php index afca009..eb79f62 100644 --- a/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php +++ b/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php @@ -637,10 +637,15 @@ public function save(EntityInterface $entity) { // Ensure the entity is still seen as new after assigning it an id, // while storing its data. $entity->enforceIsNew(); - $values[$this->idKey] = $this->database + $insert_id = $this->database ->insert($this->baseTable, array('return' => Database::RETURN_INSERT_ID)) ->fields($values) ->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. + if (!isset($values[$this->idKey])) { + $values[$this->idKey] = $insert_id; + } $return = SAVED_NEW; $entity->{$this->idKey}->value = (string) $values[$this->idKey]; if ($this->revisionTable) { @@ -810,10 +815,15 @@ protected function saveRevision(ContentEntityInterface $entity) { $entity->preSaveRevision($this, $values); if ($entity->isNewRevision()) { - $values[$this->revisionKey] = $this->database + $insert_id = $this->database ->insert($this->revisionTable, array('return' => Database::RETURN_INSERT_ID)) ->fields($values) ->execute(); + // Even if this is a new revsision, the revision ID key might have been + // set in which case we should not override the provided revision ID. + if (!isset($values[$this->revisionKey])) { + $values[$this->revisionKey] = $insert_id;; + } if ($entity->isDefaultRevision()) { $this->database->update($this->entityType->getBaseTable()) ->fields(array($this->revisionKey => $values[$this->revisionKey]))