Verified Commit 3f6a61e7 authored by alexpott's avatar alexpott
Browse files

Issue #3252100 by amateescu, catch, Tim Bozeman: Set revision_default when publishing

(cherry picked from commit 29856d74)
parent 00991b9d
......@@ -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());
}
......
......@@ -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());
}
......
......@@ -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());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment