Skip to content
Snippets Groups Projects
Commit 166ca820 authored by catch's avatar catch
Browse files

Issue #3220784 by berdir, johnchque, mathilde_dumond, dww, quietone:...

Issue #3220784 by berdir, johnchque, mathilde_dumond, dww, quietone: ContentEntityBase::createDuplicate() should reset default revision flag

(cherry picked from commit e5a67b91)
parent 1f1970a9
No related branches found
No related tags found
No related merge requests found
Pipeline #396649 passed with warnings
Pipeline: drupal

#396689

    Pipeline: drupal

    #396683

      Pipeline: drupal

      #396671

        +1
        ......@@ -1185,7 +1185,11 @@ public function createDuplicate() {
        if ($entity_type->hasKey('id')) {
        $duplicate->{$entity_type->getKey('id')}->value = NULL;
        }
        // Explicitly mark the entity as new and the default revision. A new entity
        // is always the default revision, but that persists only until the entity
        // is saved.
        $duplicate->enforceIsNew();
        $duplicate->isDefaultRevision(TRUE);
        // Check if the entity type supports UUIDs and generate a new one if so.
        if ($entity_type->hasKey('uuid')) {
        ......
        ......@@ -44,7 +44,13 @@ public function testDuplicateNonDefaultRevision(): void {
        $duplicate_first_revision = $this->entityTestRevStorage->loadRevision($first_revision_id)->createDuplicate();
        $this->assertTrue($duplicate_first_revision->isDefaultRevision(), 'Duplicating a non-default revision creates a default revision.');
        $this->assertEquals('First Revision', $duplicate_first_revision->label());
        $this->assertTrue($duplicate_first_revision->isNew());
        $this->assertTrue($duplicate_first_revision->isNewRevision());
        $this->assertTrue($duplicate_first_revision->isDefaultRevision());
        $duplicate_first_revision->save();
        $this->assertFalse($duplicate_first_revision->isNew());
        $this->assertFalse($duplicate_first_revision->isNewRevision());
        $this->assertTrue($duplicate_first_revision->isDefaultRevision());
        $duplicate_first_revision->name = 'Updated name';
        $duplicate_first_revision->save();
        ......@@ -52,6 +58,14 @@ public function testDuplicateNonDefaultRevision(): void {
        $this->entityTestRevStorage->resetCache();
        $duplicate_first_revision = EntityTestRev::load($duplicate_first_revision->id());
        $this->assertEquals('Updated name', $duplicate_first_revision->label());
        // Also ensure the base table storage by doing an entity query for the
        // updated name field.
        $results = \Drupal::entityQuery('entity_test_rev')
        ->condition('name', 'Updated name')
        ->accessCheck(FALSE)
        ->execute();
        $this->assertEquals([$duplicate_first_revision->getRevisionId() => $duplicate_first_revision->id()], $results);
        }
        }
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Finish editing this message first!
        Please register or to comment