Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
When working on #2766957: Forward revisions + translation UI can result in forked draft revisions I found that a revision was getting set as default when it shouldn't be.
This seems unrelated to the original issue, because it is caused by content moderation, rather than being exposed by content moderation. The issue also happens without the patch from the other issue.
Proposed resolution
Fix \Drupal\content_moderation\EntityOperations::entityPresave
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#18 | 2862988-18.patch | 6.8 KB | timmillwood |
#18 | interdiff-2862988-18.txt | 3.11 KB | timmillwood |
Comments
Comment #2
timmillwoodComment #3
timmillwoodI *think* this proves the issue.
I have a feeling a simpler test is needed to make it clearer.
Comment #4
catchSince this is blocking another critical issue, and it's data-integrity, bumping to critical too. Thanks for splitting this out.
Comment #6
timmillwoodFound the cause of the issue!
In
\Drupal\content_moderation\EntityOperations::isDefaultRevisionPublished
we check if the default revision is has a published state or not. This is used to set a new revision as default if the existing default is not published.This issue comes when the default revision of a language is not published, but another language of the default revision is published.
I guess the solution is to loop through all languages to see if any language of the default revision has a published state.
Comment #7
timmillwoodAdded a new simple test for this, and a fix.
Comment #10
timmillwoodoops.
Comment #13
timmillwoodTrying to debug the failing test in
\Drupal\Tests\content_moderation\Functional\ModerationLocaleTest::testTranslateModeratedContent
and it seems like the update is preventing a new translation becoming the default revision because one of the other languages is published.Comment #14
timmillwoodThis should fix the failing tests by always setting a default revision if it's a new translation, however this introduces a new bug, which will be "fixed" by #2766957: Forward revisions + translation UI can result in forked draft revisions so will add a test for it there.
Comment #15
catchNice find!
Very quick review of the patch itself:
This comment is no longer true.
Would be good to adapt this comment rather than remove it.
Comment #16
timmillwoodJust want to clarify the new bug in #14.
Imagine this case
The site has two languages, when adding an entity revision 1 is published in english, but doesn't yet have a french translation. In revision two we add an unpublished forward / draft revision for english, french still doesn't have a revision. After the patch in #14 if we add any french revision (published or unpublished) it will become the default revision. This will copy revision 1 english loosing revision 2. This is the same issue #2766957: Forward revisions + translation UI can result in forked draft revisions is trying to fix, and not really a new issue, but just a new way of causing it.
Comment #17
dawehnerInteresting find!
I guess we should update the documentation here.
Comment #18
timmillwoodFixing #15 and #17. Also tidying up isDefaultRevisionPublished a little.
Comment #19
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation commentedCode & test makes sense to me.
Comment #20
alexpottCommitted and pushed 55e309f to 8.4.x and f5b24ee to 8.3.x. Thanks!
It always feels weird that default revision is not translatable and publishing status is. Nice to have more testing in this very complex area.