diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index ad6bd80..4eb2a87 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -264,12 +264,6 @@ public function setNewRevision($value = TRUE) { throw new \LogicException("Entity type {$this->getEntityTypeId()} does not support revisions."); } - // If there is an revision ID set it as the original revision ID. Even when - // a new revision isn't created the original ID should be set. - if ($this->getRevisionId()) { - $this->originalRevisionId = $this->getRevisionId(); - } - 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. @@ -396,6 +390,12 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) { } } $this->translations = array_diff_key($this->translations, $removed); + + // If there is an revision ID set it as the original revision ID. Even when + // a new revision isn't created the original ID should be set. + if ($this->getRevisionId()) { + $this->originalRevisionId = $this->getRevisionId(); + } } /** 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 717bdb9..d9255c6 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -414,15 +414,6 @@ function entity_test_entity_test_insert($entity) { } /** - * Implements hook_entity_update(). - */ -function entity_test_entity_update(EntityInterface $entity) { - if ($entity instanceof ContentEntityInterface) { - \Drupal::state()->set('entity_test.originalRevisionId', $entity->getOriginalRevisionId()); - } -} - -/** * Implements hook_entity_field_access(). * * @see \Drupal\system\Tests\Entity\FieldAccessTest::testFieldAccess() diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityOriginalRevisionTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityOriginalRevisionTest.php index 33fc951..6ec3af0 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityOriginalRevisionTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityOriginalRevisionTest.php @@ -49,13 +49,6 @@ public function testOriginalRevisionId() { $loaded->save(); - // In entity_test_entity_update() the original revision id was stored in - // state. This should be the same as we had before calling $loaded->save(). - /** @var \Drupal\Core\Entity\ContentEntityInterface $loaded_original */ - $originalRevisionId = \Drupal::state()->get('entity_test.originalRevisionId'); - $this->assertEquals($entity->getRevisionId(), $originalRevisionId); - $this->assertNotEquals($loaded->getRevisionId(), $originalRevisionId); - // The revision ID and original revision ID should be different for the two // versions of the entity, but the same for a saved entity. $this->assertNotEquals($loaded->getRevisionId(), $entity->getRevisionId()); @@ -71,12 +64,9 @@ public function testOriginalRevisionId() { $loaded->save(); - // After saving, the original revision id set in entity_test_entity_update() - // and returned from the entity should be the same and the entity's revision - // id because a new revision wasn't created, the existing revision was - // updated. - $originalRevisionId2 = \Drupal::state()->get('entity_test.originalRevisionId'); - $this->assertEquals($loaded->getRevisionId(), $originalRevisionId2); + // After saving, the original revision id returned from the entity should be + // the same and the entity's revision id because a new revision wasn't + // created, the existing revision was updated. $this->assertEquals($loaded->getRevisionId(), $loaded->getOriginalRevisionId()); $duplicate = $loaded->createDuplicate();