diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php index 5aa737d..e9c6776 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php @@ -15,24 +15,6 @@ interface ConfigEntityInterface extends EntityInterface { /** - * Returns the original ID. - * - * @return string|null - * The original ID, if any. - */ - public function getOriginalId(); - - /** - * Sets the original ID. - * - * @param string $id - * The new ID to set as original ID. - * - * @return self - */ - public function setOriginalId($id); - - /** * Enables the configuration entity. * * @return \Drupal\Core\Config\Entity\ConfigEntityInterface diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php index 8a26ec0..5e80d88 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php @@ -307,8 +307,7 @@ public function save(EntityInterface $entity) { } if (!$config->isNew() && !isset($entity->original)) { - $this->resetCache(array($id)); - $entity->original = $this->load($id); + $entity->original = $this->loadUnchanged($id); } if ($id !== $entity->id()) { diff --git a/core/lib/Drupal/Core/Entity/DatabaseStorageController.php b/core/lib/Drupal/Core/Entity/DatabaseStorageController.php index 2056ae1..2db9db5 100644 --- a/core/lib/Drupal/Core/Entity/DatabaseStorageController.php +++ b/core/lib/Drupal/Core/Entity/DatabaseStorageController.php @@ -299,7 +299,11 @@ public function save(EntityInterface $entity) { try { // Load the stored entity, if any. if (!$entity->isNew() && !isset($entity->original)) { - $entity->original = entity_load_unchanged($this->entityTypeId, $entity->id()); + $id = $entity->id(); + if ($entity->getOriginalId() !== NULL) { + $id = $entity->getOriginalId(); + } + $entity->original = $this->loadUnchanged($id); } $entity->preSave($this); diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index 27f9895..4fa40b0 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -422,4 +422,20 @@ public function __sleep() { return array_keys(get_object_vars($this)); } + /** + * {@inheritdoc} + */ + public function getOriginalId() { + // By default, entities do not support the tracking of original IDs. + return NULL; + } + + /** + * {@inheritdoc} + */ + public function setOriginalId($id) { + // By default, entities do not support the tracking of original IDs. + return $this; + } + } diff --git a/core/lib/Drupal/Core/Entity/EntityInterface.php b/core/lib/Drupal/Core/Entity/EntityInterface.php index 057727b..cabb271 100644 --- a/core/lib/Drupal/Core/Entity/EntityInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityInterface.php @@ -297,4 +297,22 @@ public function getEntityType(); */ public function referencedEntities(); + /** + * Returns the original ID. + * + * @return int|string|null + * The original ID, if any. + */ + public function getOriginalId(); + + /** + * Sets the original ID. + * + * @param int|string|null $id + * The new ID to set as original ID. + * + * @return $this + */ + public function setOriginalId($id); + } diff --git a/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php b/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php index eaa4951..31b1613 100644 --- a/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php +++ b/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php @@ -536,7 +536,11 @@ public function save(EntityInterface $entity) { // Load the stored entity, if any. if (!$entity->isNew() && !isset($entity->original)) { - $entity->original = entity_load_unchanged($this->entityTypeId, $entity->id()); + $id = $entity->id(); + if ($entity->getOriginalId() !== NULL) { + $id = $entity->getOriginalId(); + } + $entity->original = $this->loadUnchanged($id); } $entity->preSave($this); diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php index 51a7241..4c420c3 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php @@ -52,7 +52,11 @@ public function save(EntityInterface $entity) { try { // Load the stored entity, if any. if (!$entity->isNew() && !isset($entity->original)) { - $entity->original = entity_load_unchanged($this->entityTypeId, $entity->id()); + $id = $entity->id(); + if ($entity->getOriginalId() !== NULL) { + $id = $entity->getOriginalId(); + } + $entity->original = $this->loadUnchanged($id); } if ($entity->isNew()) {