diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index 7a4a4b0..dd6481e 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -278,6 +278,7 @@ public function preSave(EntityStorageInterface $storage) { throw new ConfigDuplicateUUIDException(String::format('Attempt to save a configuration entity %id with UUID %uuid when this UUID is already used for %matched', array('%id' => $this->id(), '%uuid' => $this->uuid(), '%matched' => $matched_entity))); } + // If this entity is not new, load the original entity for comparison. if (!$this->isNew()) { $original = $storage->loadUnchanged($this->getOriginalId()); // Ensure that the UUID cannot be changed for an existing entity. diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php index 9a3bf63..2703632 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php @@ -357,7 +357,9 @@ public function save(EntityInterface $entity) { $this->invokeHook('insert', $entity); } - // Immediately update the original ID. + // After saving, this is now the "original entity", and subsequent saves + // will be updates instead of inserts, and updates must always be able to + // correctly identify the original entity. $entity->setOriginalId($entity->id()); unset($entity->original); diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index ccd4afa..5e43af3 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -313,6 +313,7 @@ public function delete() { public function createDuplicate() { $duplicate = clone $this; $entity_type = $this->getEntityType(); + // Reset the entity ID and indicate that this is a new entity. $duplicate->{$entity_type->getKey('id')} = NULL; $duplicate->enforceIsNew(); diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php index 3f158db..5fa0260 100644 --- a/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php @@ -109,6 +109,8 @@ class Breakpoint extends ConfigEntityBase implements BreakpointInterface { * {@inheritdoc} */ public function id() { + // If no ID is specified, build one from the properties that uniquely define + // this breakpoint. if (!isset($this->id)) { $this->id = $this->sourceType . '.' . $this->source . '.' . $this->name; } diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php index 2f137b2..595ca76 100644 --- a/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php @@ -111,6 +111,8 @@ public function save() { * {@inheritdoc} */ public function id() { + // If no ID is specified, build one from the properties that uniquely define + // this breakpoint group. if (!isset($this->id)) { $this->id = $this->sourceType . '.' . $this->source . '.' . $this->name; }