diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index 7c0a458..6beb172 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -266,6 +266,7 @@ public function setNewRevision($value = TRUE) { if ($value && !$this->newRevision) { // When saving a new revision, set any existing revision ID to NULL so as // to ensure that a new revision will actually be created. + $this->original_revision = $this->getRevisionId(); $this->set($this->getEntityType()->getKey('revision'), NULL); // Make sure that the flag tracking which translations are affected by the diff --git a/core/lib/Drupal/Core/Entity/EntityStorageBase.php b/core/lib/Drupal/Core/Entity/EntityStorageBase.php index f583121..edc9fda 100644 --- a/core/lib/Drupal/Core/Entity/EntityStorageBase.php +++ b/core/lib/Drupal/Core/Entity/EntityStorageBase.php @@ -427,7 +427,13 @@ protected function doPreSave(EntityInterface $entity) { // Load the original entity, if any. if ($id_exists && !isset($entity->original)) { - $entity->original = $this->loadUnchanged($id); + if (isset($entity->original_revision)) { + $entity->original = $this->loadRevision($entity->original_revision); + unset($entity->original_revision); + } + else { + $entity->original = $this->loadUnchanged($id); + } } // Allow code to run before saving. diff --git a/core/modules/system/tests/modules/entity_test/entity_test.module b/core/modules/system/tests/modules/entity_test/entity_test.module index 453bdf1..241df61 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -399,6 +399,13 @@ function entity_test_entity_test_insert($entity) { } /** + * Implements hook_entity_update(). + */ +function entity_test_entity_update(EntityInterface $entity) { + \Drupal::state()->set('entity_test.original', $entity->original); +} + +/** * Implements hook_entity_field_access(). * * @see \Drupal\system\Tests\Entity\FieldAccessTest::testFieldAccess()