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) {
// 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) {
// Check that there are no more revisions to push.
......@@ -261,4 +261,32 @@ public function testIsLatestAffectedRevisionTranslation() {
* 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();
// Create a new default revision.
// Create a new non-default revision.
// Turn the previous non-default revision into a default revision.
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