Loading core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php +6 −4 Original line number Diff line number Diff line Loading @@ -708,10 +708,12 @@ protected function doSave($id, EntityInterface $entity) { $this->populateAffectedRevisionTranslations($entity); // Populate the "revision_default" flag. We skip this when we are resaving // the revision because this is only allowed for default revisions, and // these cannot be made non-default. if ($this->entityType->isRevisionable() && $entity->isNewRevision()) { // Populate the "revision_default" flag. Skip this when we are resaving // the revision, and the flag is set to FALSE, since it is not possible to // set a previously default revision to non-default. However, setting a // previously non-default revision to default is allowed for advanced // use-cases. if ($this->entityType->isRevisionable() && ($entity->isNewRevision() || $entity->isDefaultRevision())) { $revision_default_key = $this->entityType->getRevisionMetadataKey('revision_default'); $entity->set($revision_default_key, $entity->isDefaultRevision()); } Loading core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php +7 −0 Original line number Diff line number Diff line Loading @@ -356,6 +356,13 @@ public function testWorkspaces() { $this->assertWorkspaceStatus($test_scenarios['push_stage_to_live'], 'node'); $this->assertWorkspaceAssociation($expected_workspace_association['push_stage_to_live'], 'node'); // Check that all the revisions that were published to 'Live' were also // marked as default revisions in their revision metadata field. $published_revisions = $this->entityTypeManager->getStorage('node')->loadMultipleRevisions(array_keys($expected['node'])); foreach ($published_revisions as $published_revision) { $this->assertTrue($published_revision->wasDefaultRevision()); } // Check that there are no more revisions to push. $this->assertEmpty($workspace_publisher->getDifferringRevisionIdsOnSource()); } Loading core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionsTest.php +28 −0 Original line number Diff line number Diff line Loading @@ -261,4 +261,32 @@ public function testIsLatestAffectedRevisionTranslation() { $this->assertTrue($en_revision->isLatestTranslationAffectedRevision()); } /** * Tests the automatic handling of the "revision_default" flag. * * @covers \Drupal\Core\Entity\ContentEntityStorageBase::doSave */ public function testDefaultRevisionFlag() { // Create a basic EntityTestMulRev entity and save it. $entity = EntityTestMulRev::create(); $entity->save(); $this->assertTrue($entity->wasDefaultRevision()); // Create a new default revision. $entity->setNewRevision(TRUE); $entity->save(); $this->assertTrue($entity->wasDefaultRevision()); // Create a new non-default revision. $entity->setNewRevision(TRUE); $entity->isDefaultRevision(FALSE); $entity->save(); $this->assertFalse($entity->wasDefaultRevision()); // Turn the previous non-default revision into a default revision. $entity->isDefaultRevision(TRUE); $entity->save(); $this->assertTrue($entity->wasDefaultRevision()); } } Loading
core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php +6 −4 Original line number Diff line number Diff line Loading @@ -708,10 +708,12 @@ protected function doSave($id, EntityInterface $entity) { $this->populateAffectedRevisionTranslations($entity); // Populate the "revision_default" flag. We skip this when we are resaving // the revision because this is only allowed for default revisions, and // these cannot be made non-default. if ($this->entityType->isRevisionable() && $entity->isNewRevision()) { // Populate the "revision_default" flag. Skip this when we are resaving // the revision, and the flag is set to FALSE, since it is not possible to // set a previously default revision to non-default. However, setting a // previously non-default revision to default is allowed for advanced // use-cases. if ($this->entityType->isRevisionable() && ($entity->isNewRevision() || $entity->isDefaultRevision())) { $revision_default_key = $this->entityType->getRevisionMetadataKey('revision_default'); $entity->set($revision_default_key, $entity->isDefaultRevision()); } Loading
core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php +7 −0 Original line number Diff line number Diff line Loading @@ -356,6 +356,13 @@ public function testWorkspaces() { $this->assertWorkspaceStatus($test_scenarios['push_stage_to_live'], 'node'); $this->assertWorkspaceAssociation($expected_workspace_association['push_stage_to_live'], 'node'); // Check that all the revisions that were published to 'Live' were also // marked as default revisions in their revision metadata field. $published_revisions = $this->entityTypeManager->getStorage('node')->loadMultipleRevisions(array_keys($expected['node'])); foreach ($published_revisions as $published_revision) { $this->assertTrue($published_revision->wasDefaultRevision()); } // Check that there are no more revisions to push. $this->assertEmpty($workspace_publisher->getDifferringRevisionIdsOnSource()); } Loading
core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionsTest.php +28 −0 Original line number Diff line number Diff line Loading @@ -261,4 +261,32 @@ public function testIsLatestAffectedRevisionTranslation() { $this->assertTrue($en_revision->isLatestTranslationAffectedRevision()); } /** * Tests the automatic handling of the "revision_default" flag. * * @covers \Drupal\Core\Entity\ContentEntityStorageBase::doSave */ public function testDefaultRevisionFlag() { // Create a basic EntityTestMulRev entity and save it. $entity = EntityTestMulRev::create(); $entity->save(); $this->assertTrue($entity->wasDefaultRevision()); // Create a new default revision. $entity->setNewRevision(TRUE); $entity->save(); $this->assertTrue($entity->wasDefaultRevision()); // Create a new non-default revision. $entity->setNewRevision(TRUE); $entity->isDefaultRevision(FALSE); $entity->save(); $this->assertFalse($entity->wasDefaultRevision()); // Turn the previous non-default revision into a default revision. $entity->isDefaultRevision(TRUE); $entity->save(); $this->assertTrue($entity->wasDefaultRevision()); } }