diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index 268f297..e242544 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -149,11 +149,11 @@ protected $validationRequired = FALSE; /** - * The original revision ID before the new revision was set. + * The loaded revision ID before the new revision was set. * * @var int */ - protected $originalRevisionId; + protected $loadedRevisionId; /** * {@inheritdoc} @@ -227,9 +227,9 @@ public function __construct(array $values, $entity_type, $bundle = FALSE, $trans } } if ($this->getEntityType()->isRevisionable()) { - // Store the original revision ID the entity has been loaded with to + // Store the loaded revision ID the entity has been loaded with to // keep it safe from changes. - $this->updateOriginalRevisionId(); + $this->updateLoadedRevisionId(); } } @@ -285,15 +285,15 @@ public function setNewRevision($value = TRUE) { /** * {@inheritdoc} */ - public function getOriginalRevisionId() { - return $this->originalRevisionId; + public function getLoadedRevisionId() { + return $this->loadedRevisionId; } /** * {@inheritdoc} */ - public function updateOriginalRevisionId() { - $this->originalRevisionId = $this->getRevisionId() ?: $this->originalRevisionId; + public function updateLoadedRevisionId() { + $this->loadedRevisionId = $this->getRevisionId() ?: $this->loadedRevisionId; return $this; } @@ -826,7 +826,7 @@ protected function initializeTranslation($langcode) { $translation->translatableEntityKeys = &$this->translatableEntityKeys; $translation->translationInitialize = FALSE; $translation->typedData = NULL; - $translation->originalRevisionId = &$this->originalRevisionId; + $translation->loadedRevisionId = &$this->loadedRevisionId; return $translation; } @@ -1053,7 +1053,7 @@ public function createDuplicate() { // Check whether the entity type supports revisions and initialize it if so. if ($entity_type->isRevisionable()) { $duplicate->{$entity_type->getKey('revision')}->value = NULL; - $duplicate->originalRevisionId = NULL; + $duplicate->loadedRevisionId = NULL; } return $duplicate; @@ -1096,10 +1096,10 @@ public function __clone() { $enforce_is_new = $this->enforceIsNew; $this->enforceIsNew = &$enforce_is_new; - // Ensure the originalRevisionId property is actually cloned by + // Ensure the loadedRevisionId property is actually cloned by // overwriting the original reference with one pointing to a copy of it. - $original_revision_id = $this->originalRevisionId; - $this->originalRevisionId = &$original_revision_id; + $original_revision_id = $this->loadedRevisionId; + $this->loadedRevisionId = &$original_revision_id; } } diff --git a/core/lib/Drupal/Core/Entity/ContentEntityInterface.php b/core/lib/Drupal/Core/Entity/ContentEntityInterface.php index 6d51070..8893a8b 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityInterface.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityInterface.php @@ -54,16 +54,16 @@ public function setRevisionTranslationAffected($affected); public function isRevisionTranslationAffected(); /** - * Gets the original revision ID of the entity. + * Gets the loaded Revision ID of the entity. * * @return int - * The original revision identifier of the entity, or NULL if the entity + * The loaded Revision identifier of the entity, or NULL if the entity * does not have a revision identifier. */ - public function getOriginalRevisionId(); + public function getLoadedRevisionId(); /** - * Updates the original revision ID with the revision ID. + * Updates the loaded Revision ID with the revision ID. * * This method should not be used, it could unintentionally cause the original * revision ID property value to be lost. @@ -72,6 +72,6 @@ public function getOriginalRevisionId(); * * @return $this */ - public function updateOriginalRevisionId(); + public function updateLoadedRevisionId(); } diff --git a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php index 79430e4..84015bf 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php @@ -305,7 +305,7 @@ protected function doPostSave(EntityInterface $entity, $update) { // The revision is stored, it should no longer be marked as new now. if ($this->entityType->isRevisionable()) { - $entity->updateOriginalRevisionId(); + $entity->updateLoadedRevisionId(); $entity->setNewRevision(FALSE); } } 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..404dd97 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -418,7 +418,7 @@ function entity_test_entity_test_insert($entity) { */ function entity_test_entity_update(EntityInterface $entity) { if ($entity instanceof ContentEntityInterface) { - \Drupal::state()->set('entity_test.originalRevisionId', $entity->getOriginalRevisionId()); + \Drupal::state()->set('entity_test.loadedRevisionId', $entity->getLoadedRevisionId()); } } diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityOriginalRevisionTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityOriginalRevisionTest.php index 6ec8cf3..9fedf26 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityOriginalRevisionTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityOriginalRevisionTest.php @@ -6,11 +6,11 @@ use Drupal\language\Entity\ConfigurableLanguage; /** - * Tests the original revision of an entity. + * Tests the loaded Revision of an entity. * * @group entity */ -class EntityOriginalRevisionTest extends EntityKernelTestBase { +class EntityLoadedRevisionTest extends EntityKernelTestBase { /** * Modules to enable. @@ -35,9 +35,9 @@ protected function setUp() { } /** - * Test getOriginalRevisionId() returns the correct ID throughout the process. + * Test getLoadedRevisionId() returns the correct ID throughout the process. */ - public function testOriginalRevisionId() { + public function testLoadedRevisionId() { ConfigurableLanguage::createFromLangcode('fr')->save(); // Create a basic EntityTestMulRev entity and save it. @@ -48,83 +48,83 @@ public function testOriginalRevisionId() { $loaded = EntityTestMulRev::load($entity->id()); $loaded->setNewRevision(TRUE); - // Before saving, the original revision ID should be the same as the created + // Before saving, the loaded Revision ID should be the same as the created // entity, not the same as the loaded entity (which does not have a revision // ID yet). - $this->assertEquals($entity->getRevisionId(), $loaded->getOriginalRevisionId()); - $this->assertNotEquals($loaded->getRevisionId(), $loaded->getOriginalRevisionId()); + $this->assertEquals($entity->getRevisionId(), $loaded->getLoadedRevisionId()); + $this->assertNotEquals($loaded->getRevisionId(), $loaded->getLoadedRevisionId()); $this->assertSame(NULL, $loaded->getRevisionId()); - // After updating the original revision ID the result should be the same. - $loaded->updateOriginalRevisionId(); - $this->assertEquals($entity->getRevisionId(), $loaded->getOriginalRevisionId()); - $this->assertNotEquals($loaded->getRevisionId(), $loaded->getOriginalRevisionId()); + // After updating the loaded Revision ID the result should be the same. + $loaded->updateLoadedRevisionId(); + $this->assertEquals($entity->getRevisionId(), $loaded->getLoadedRevisionId()); + $this->assertNotEquals($loaded->getRevisionId(), $loaded->getLoadedRevisionId()); $this->assertSame(NULL, $loaded->getRevisionId()); $loaded->save(); - // In entity_test_entity_update() the original revision ID was stored in + // In entity_test_entity_update() the loaded 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); + $loadedRevisionId = \Drupal::state()->get('entity_test.loadedRevisionId'); + $this->assertEquals($entity->getRevisionId(), $loadedRevisionId); + $this->assertNotEquals($loaded->getRevisionId(), $loadedRevisionId); - // The revision ID and original revision ID should be different for the two + // The revision ID and loaded 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()); - $this->assertNotEquals($loaded->getOriginalRevisionId(), $entity->getOriginalRevisionId()); - $this->assertEquals($entity->getRevisionId(), $entity->getOriginalRevisionId()); - $this->assertEquals($loaded->getRevisionId(), $loaded->getOriginalRevisionId()); + $this->assertNotEquals($loaded->getLoadedRevisionId(), $entity->getLoadedRevisionId()); + $this->assertEquals($entity->getRevisionId(), $entity->getLoadedRevisionId()); + $this->assertEquals($loaded->getRevisionId(), $loaded->getLoadedRevisionId()); // Make a change to the loaded entity. $loaded->set('name', 'dublin'); - // The revision id and original revision id should still be the same. - $this->assertEquals($loaded->getRevisionId(), $loaded->getOriginalRevisionId()); + // The revision id and loaded Revision id should still be the same. + $this->assertEquals($loaded->getRevisionId(), $loaded->getLoadedRevisionId()); $loaded->save(); - // After saving, the original revision id set in entity_test_entity_update() + // After saving, the loaded Revision id set in entity_test_entity_update() // and returned from the entity should be the same as 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()); + $loadedRevisionId2 = \Drupal::state()->get('entity_test.loadedRevisionId'); + $this->assertEquals($loaded->getRevisionId(), $loadedRevisionId2); + $this->assertEquals($loaded->getRevisionId(), $loaded->getLoadedRevisionId()); - // Creating a clone should keep the original revision ID. + // Creating a clone should keep the loaded Revision ID. $clone = clone $loaded; - $this->assertSame($loaded->getOriginalRevisionId(), $clone->getOriginalRevisionId()); + $this->assertSame($loaded->getLoadedRevisionId(), $clone->getLoadedRevisionId()); - // Creating a duplicate should set a NULL original revision ID. + // Creating a duplicate should set a NULL loaded Revision ID. $duplicate = $loaded->createDuplicate(); - $this->assertSame(NULL, $duplicate->getOriginalRevisionId()); + $this->assertSame(NULL, $duplicate->getLoadedRevisionId()); // Check it all works with translations. $french = $loaded->addTranslation('fr'); // Adding a revision should return the same for each language. - $this->assertEquals($french->getRevisionId(), $french->getOriginalRevisionId()); - $this->assertEquals($loaded->getRevisionId(), $french->getOriginalRevisionId()); - $this->assertEquals($loaded->getOriginalRevisionId(), $french->getOriginalRevisionId()); + $this->assertEquals($french->getRevisionId(), $french->getLoadedRevisionId()); + $this->assertEquals($loaded->getRevisionId(), $french->getLoadedRevisionId()); + $this->assertEquals($loaded->getLoadedRevisionId(), $french->getLoadedRevisionId()); $french->save(); // After saving nothing should change. - $this->assertEquals($french->getRevisionId(), $french->getOriginalRevisionId()); - $this->assertEquals($loaded->getRevisionId(), $french->getOriginalRevisionId()); - $this->assertEquals($loaded->getOriginalRevisionId(), $french->getOriginalRevisionId()); + $this->assertEquals($french->getRevisionId(), $french->getLoadedRevisionId()); + $this->assertEquals($loaded->getRevisionId(), $french->getLoadedRevisionId()); + $this->assertEquals($loaded->getLoadedRevisionId(), $french->getLoadedRevisionId()); $first_revision_id = $french->getRevisionId(); $french->setNewRevision(); - // Setting a new revision will reset the original revision ID. - $this->assertEquals($first_revision_id, $french->getOriginalRevisionId()); - $this->assertEquals($first_revision_id, $loaded->getOriginalRevisionId()); - $this->assertNotEquals($french->getRevisionId(), $french->getOriginalRevisionId()); - $this->assertGreaterThan($french->getRevisionId(), $french->getOriginalRevisionId()); - $this->assertNotEquals($loaded->getRevisionId(), $loaded->getOriginalRevisionId()); - $this->assertGreaterThan($loaded->getRevisionId(), $loaded->getOriginalRevisionId()); + // Setting a new revision will reset the loaded Revision ID. + $this->assertEquals($first_revision_id, $french->getLoadedRevisionId()); + $this->assertEquals($first_revision_id, $loaded->getLoadedRevisionId()); + $this->assertNotEquals($french->getRevisionId(), $french->getLoadedRevisionId()); + $this->assertGreaterThan($french->getRevisionId(), $french->getLoadedRevisionId()); + $this->assertNotEquals($loaded->getRevisionId(), $loaded->getLoadedRevisionId()); + $this->assertGreaterThan($loaded->getRevisionId(), $loaded->getLoadedRevisionId()); $french->save(); // Saving the new revision will reset the origin revision ID again. - $this->assertEquals($french->getRevisionId(), $french->getOriginalRevisionId()); - $this->assertEquals($loaded->getRevisionId(), $loaded->getOriginalRevisionId()); + $this->assertEquals($french->getRevisionId(), $french->getLoadedRevisionId()); + $this->assertEquals($loaded->getRevisionId(), $loaded->getLoadedRevisionId()); } }