diff --cc core/lib/Drupal/Core/Entity/ContentEntityBase.php index 7c0a458,4eb2a87..0000000 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@@ -368,6 -376,31 +387,19 @@@ abstract class ContentEntityBase extend /** * {@inheritdoc} */ + public function postSave(EntityStorageInterface $storage, $update = TRUE) { + parent::postSave($storage, $update); + - // Update the status of all saved translations. - $removed = []; - foreach ($this->translations as $langcode => &$data) { - if ($data['status'] == static::TRANSLATION_REMOVED) { - $removed[$langcode] = TRUE; - } - else { - $data['status'] = static::TRANSLATION_EXISTING; - } - } - $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(); + } + } + + /** + * {@inheritdoc} + */ public function validate() { $this->validated = TRUE; $violations = $this->getTypedData()->validate(); 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 d9255c6..4192e33 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -482,6 +482,10 @@ function entity_test_entity_presave(EntityInterface $entity) { if ($entity->getEntityType()->id() == 'entity_view_display') { $entity->setThirdPartySetting('entity_test', 'foo', 'bar'); } + + 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 6ec3af0..cd0fcc6 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityOriginalRevisionTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityOriginalRevisionTest.php @@ -49,6 +49,13 @@ public function testOriginalRevisionId() { $loaded->save(); + // In entity_test_entity_presave() 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()); @@ -64,9 +71,12 @@ public function testOriginalRevisionId() { $loaded->save(); - // 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. + // After saving, the original revision id set in + // entity_test_entity_presave() 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()); $duplicate = $loaded->createDuplicate(); diff --git a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php index bc5965b..cb73533 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(6)) + $this->entityType->expects($this->at(5)) ->method('getKey') ->with('revision') ->will($this->returnValue('revision_id'));