ContentEntityBase::createDuplicate() should reset default revision flag

Created on 25 June 2021, over 3 years ago
Updated 2 February 2023, almost 2 years ago

Problem/Motivation

Creating a duplicate of a content entity does not reset the default revision flag. That's not initially a problem as a new entity is enforced to be a default revision, but if you duplicate and then save an entity twice, extremely weird things happen because only the revision table is updated.

While this may sound like a weird thing to do, it is happening for us in context of paragraphs for example, where we had troubles when a paragraph was saved as non-default but not actually as a new revision.

The reason for that is that \Drupal\content_moderation\EntityTypeInfo::entityPrepareForm() switches the entity into a non-default revision (I don't really understand why, but that's a different topic), and then ERR ensures that all referenced paragraphs are in a non-default revision as well, then they are stored in form state. When you then duplicate a paragraph and change it at the same time, it does properly persist the changes. See #3198091: Changes of newly replicated Paragraphs are not saved . There is more going on there, but I think this change makes sense to do anyway.

Funny enough, we already "fixed" this in #2850022: Duplicating a non-default revision should produce a default revision for a newly created entity and we have a test for it: \Drupal\KernelTests\Core\Entity\EntityDuplicateTest::testDuplicateNonDefaultRevision. But we fixed it by checking isNew() in the isDefaultRevision() method, so the double save edge case is not covered yet.

Steps to reproduce

Proposed resolution

Remaining tasks

Extend the test by changing the saved entity again and resaving it.

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Needs review

Version

10.1

Component
Entity 

Last updated about 12 hours ago

Created by

🇨🇭Switzerland berdir Switzerland

Live updates comments and jobs are added and updated live.

Missing content requested by

🇦🇺Australia dpi
about 1 year ago
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024