Verified Commit 29856d74 authored by Alex Pott's avatar Alex Pott
Browse files

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

parent f081cdb3
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -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());
    }
+7 −0
Original line number Diff line number Diff line
@@ -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());
  }
+28 −0
Original line number Diff line number Diff line
@@ -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());
  }

}