Skip to content
Snippets Groups Projects
Commit 886ee4e3 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 7a37ca1e
No related branches found
No related tags found
13 merge requests!11515Issue #3480419 by mondrake, smustgrave, catch: Method...,!11380Issue #3490698 by catch, spokje: Bump MINIMUM_STABILITY back to 'stable' when...,!11281Use Drupal Core Leadership terminology in MAINTAINERS.txt,!11239Issue #3507548: Allow workspace changes listing to show all items, without a pager,!11238Fix issue #3051797,!11213Issue #3506743 by tomislav.matokovic: Increasing the color contrast for the navigation block title against the background of the navigation sidebar to at least 4.5:1,!11147Draft: Try to avoid manually setting required cache contexts,!11108Issue #3490298 by nicxvan: Profiles can be missed in OOP hooks,!11093Drupal on MongoDB 11.1.x,!11017Issue #3502540: Add date filter for moderated content.,!11009Issue #3486972 migrate feed icon,!10999Cleaning up Taxonomy hooks and updating baseline.,!10977Issue #3501457: Fix path used in a A11y Test Admin
Pipeline #396788 canceled
Pipeline: drupal

#396789

    ...@@ -1184,7 +1184,11 @@ public function createDuplicate() { ...@@ -1184,7 +1184,11 @@ public function createDuplicate() {
    if ($entity_type->hasKey('id')) { if ($entity_type->hasKey('id')) {
    $duplicate->{$entity_type->getKey('id')}->value = NULL; $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->enforceIsNew();
    $duplicate->isDefaultRevision(TRUE);
    // Check if the entity type supports UUIDs and generate a new one if so. // Check if the entity type supports UUIDs and generate a new one if so.
    if ($entity_type->hasKey('uuid')) { if ($entity_type->hasKey('uuid')) {
    ......
    ...@@ -44,7 +44,13 @@ public function testDuplicateNonDefaultRevision(): void { ...@@ -44,7 +44,13 @@ public function testDuplicateNonDefaultRevision(): void {
    $duplicate_first_revision = $this->entityTestRevStorage->loadRevision($first_revision_id)->createDuplicate(); $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->assertTrue($duplicate_first_revision->isDefaultRevision(), 'Duplicating a non-default revision creates a default revision.');
    $this->assertEquals('First Revision', $duplicate_first_revision->label()); $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(); $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->name = 'Updated name';
    $duplicate_first_revision->save(); $duplicate_first_revision->save();
    ...@@ -52,6 +58,14 @@ public function testDuplicateNonDefaultRevision(): void { ...@@ -52,6 +58,14 @@ public function testDuplicateNonDefaultRevision(): void {
    $this->entityTestRevStorage->resetCache(); $this->entityTestRevStorage->resetCache();
    $duplicate_first_revision = EntityTestRev::load($duplicate_first_revision->id()); $duplicate_first_revision = EntityTestRev::load($duplicate_first_revision->id());
    $this->assertEquals('Updated name', $duplicate_first_revision->label()); $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