diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index 7fb987e..27026ea 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -275,7 +275,11 @@ public function setNewRevision($value = TRUE) { throw new \LogicException("Entity type {$this->getEntityTypeId()} does not support revisions."); } - $this->originalRevisionId = $this->getRevisionId(); + // 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 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 e4e9b7e..717bdb9 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -6,6 +6,7 @@ */ use Drupal\Core\Access\AccessResult; +use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\EntityTypeInterface; @@ -416,7 +417,7 @@ function entity_test_entity_test_insert($entity) { * Implements hook_entity_update(). */ function entity_test_entity_update(EntityInterface $entity) { - if ($entity instanceof \Drupal\Core\Entity\OriginalRevisionIdInterface) { + if ($entity instanceof ContentEntityInterface) { \Drupal::state()->set('entity_test.originalRevisionId', $entity->getOriginalRevisionId()); } } diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityOriginalRevisionTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityOriginalRevisionTest.php index 38aa639..6ecda26 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityOriginalRevisionTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityOriginalRevisionTest.php @@ -49,8 +49,8 @@ public function testOriginalRevisionId() { $loaded->save(); - // In entity_test_update() the original revision id was stored in state. - // This should be the same as we had before calling $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); @@ -71,9 +71,10 @@ public function testOriginalRevisionId() { $loaded->save(); - // After saving, the original revision id set in entity_test_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. + // 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); $this->assertEquals($loaded->getRevisionId(), $loaded->getOriginalRevisionId()); diff --git a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php index cb73533..bc5965b 100644 --- a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php @@ -215,7 +215,7 @@ public function testIsNewRevision() { ->method('hasKey') ->with('revision') ->will($this->returnValue(TRUE)); - $this->entityType->expects($this->at(5)) + $this->entityType->expects($this->at(6)) ->method('getKey') ->with('revision') ->will($this->returnValue('revision_id'));