diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index 6beb172..aed081a 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -266,7 +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->previous_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 edc9fda..880bc9b 100644 --- a/core/lib/Drupal/Core/Entity/EntityStorageBase.php +++ b/core/lib/Drupal/Core/Entity/EntityStorageBase.php @@ -427,13 +427,13 @@ protected function doPreSave(EntityInterface $entity) { // Load the original entity, if any. if ($id_exists && !isset($entity->original)) { - if (isset($entity->original_revision)) { - $entity->original = $this->loadRevision($entity->original_revision); - unset($entity->original_revision); - } - else { - $entity->original = $this->loadUnchanged($id); - } + $entity->original = $this->loadUnchanged($id); + } + + // Load the previous revision, if any. + if ($id_exists && !isset($entity->previous)) { + $entity->previous = $this->loadRevision($entity->original_revision); + unset($entity->original_revision); } // Allow code to run before saving. @@ -481,6 +481,7 @@ protected function doPostSave(EntityInterface $entity, $update) { $entity->setOriginalId($entity->id()); unset($entity->original); + unset($entity->previous); } /** 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 241df61..46ddd90 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -402,7 +402,7 @@ 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); + \Drupal::state()->set('entity_test.previous', $entity->previous); } /** diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityPreviousPropertyTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityPreviousPropertyTest.php index 8f85745..d9f6632 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityPreviousPropertyTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityPreviousPropertyTest.php @@ -5,11 +5,11 @@ use Drupal\entity_test\Entity\EntityTestMulRev; /** - * Tests the original property on an entity. + * Tests the previous property on an entity. * * @group entity */ -class EntityOriginalPropertyTest extends EntityKernelTestBase { +class EntityPreviousPropertyTest extends EntityKernelTestBase { /** * Modules to enable. @@ -28,7 +28,7 @@ protected function setUp() { } - public function testOriginalProperty() { + public function testPreviousProperty() { $entity = EntityTestMulRev::create(); $entity->save(); @@ -36,15 +36,14 @@ public function testOriginalProperty() { $loaded->setNewRevision(TRUE); $loaded->save(); - /** @var \Drupal\Core\Entity\ContentEntityInterface $loaded_original */ - $original = \Drupal::state()->get('entity_test.original'); - $this->assertEquals($entity->getRevisionId(), $original->getRevisionId()); - $this->assertNotEquals($loaded->getRevisionId(), $original->getRevisionId()); + /** @var \Drupal\Core\Entity\ContentEntityInterface $loaded_previous */ + $previous = \Drupal::state()->get('entity_test.previous'); + $this->assertEquals($entity->getRevisionId(), $previous->getRevisionId()); + $this->assertNotEquals($loaded->getRevisionId(), $previous->getRevisionId()); $loaded->set('name', 'dublin'); $loaded->save(); - $original2 = \Drupal::state()->get('entity_test.original'); - $this->assertEquals($loaded->getRevisionId(), $original2->getRevisionId()); - + $previous2 = \Drupal::state()->get('entity_test.previous'); + $this->assertEquals($loaded->getRevisionId(), $previous2->getRevisionId()); } }