Closed (duplicate)
Project:
Drupal core
Version:
9.1.x-dev
Component:
content_moderation.module
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
3 Apr 2019 at 19:00 UTC
Updated:
12 Jun 2020 at 05:18 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
bklineComment #3
sam152 commentedIt does use the configured default moderation state? It's only hard-coded when the entity already had publishing values before moderation was enabled.
Am I missing something?
Comment #4
bklineThe "entity" (meaning the content item with all its translations) may not be new, and some of its translations may already have moderation state history. However, when the translation being saved is new, it is supposed to start off with the initial default moderation state configured for the workflow connected with the content item's type. Each translation has its own workflow history, which is supposed to be independent of where the other translations are in the workflow (as can be seen by examining the database tables).
Even though the
$entitybeing passed into this method represents the individual translation, the implementation of theisNew()method is answering the question for the entire content item with all its translations, not for this translation. If you have a node (or media or any other entity type instance) for which 50 revisions exist in English, and a new Swedish translation is being created, for which no rows exist in any of the database tables, the answer you get back when you invokeisNew()on an object representing this new translation will beFALSE, becauseisNew()answers the question by checking to see whether there is an entity ID for the content item. In our context, that's not the answer to the question we need to have answered. We need to know if the translation represented by the object is new.Does this help clear things up?
Comment #5
bklineAh, I see the use case the code was trying to address (content which existed before
content_moderationis installed/enabled). Let me re-roll a patch which handles that case if the translation being saved is really not being saved for the first time.Comment #6
bklineComment #7
bklineComment #9
bklineComment #10
bklineModified patch to avoid querying the revision table for entity types which do not support revisions.
Comment #12
bklineWell, the number of failures is decreasing, so at least I'm moving in the right direction. If I can figure out how to run the tests locally, that will help.
Comment #13
bklineWell, I'm making good progress. I've figured out how to run the tests locally. And apparently
EntityTypeInterface::isRevisionable()doesn't mean what I thought it meant. 😉Comment #15
bklineThis patch passes the tests on my local instance (the previous version cast its net too wide in looking for publishable revisions).
Comment #16
sam152 commentedI think a functional test illustrating where the state is being initialised incorrectly according to your use-case would be helpful in understanding this. I'm lukewarm on adding this much complexity to a fairly low level part of the module unless there is a pretty glaring bug which makes the system unusable without it.
Comment #17
bklineI have created the functional test for this ticket. However, it will not pass, even with the rest of the patch, until several other bugs have been corrected (either separately, or by being folded into this issue).
The test case creates a workflow with three states: draft, published, and editing, with the default initial state set to draft. The allowed transitions are:
This workflow is a much abbreviated version of the workflow in our system, reduced to follow the principle of including only as much as necessary in a repro case.
The test ...
The expected behavior runs into a number of hurdles along the way.
The first problem is that when the user clicks the
Translatelink the form which is generated has a picklist which contains the wrong set of valid values, and anInvalidArgumentExceptionis thrown with the following error message:This happens because the
content_moderationmodule thinks that because the original English version of the node is published, the only valid state for the French translation is editing, as if the new translation's moderation state were not supposed to be tracked separately from the other language translations of the node. This bug is reported as https://www.drupal.org/project/drupal/issues/3021222.I suppressed this bug by including in the patch a testing module with an
entity_translation_createhook to change the initial moderation state value from 'published' to the default value for the state.After getting past that first hurdle, the test is now able to set the state of the moderation field for saving the translation as "draft" without triggering the
InvalidArgumentExceptionthrown by the form validation. The test then encounters a second bug, which is that, even though content moderation was not enabled until after the English node was saved, and all four of the new content_moderation_* tables are empty, theisFirstTimeModeration()method returns FALSE, because the loaded$original_entityobject has amoderation_statefield value set to "published," which is made up from the field definition. The result of this second bug is that, even though this is the first save with moderation of any translation, and we should proceed to invoking the workflow type'sgetInitialState()method, we never get that far, and the software thinks the user is trying to transition from published to draft, which is not an allowed transition for this workflow.The fix for this bug would be to use an entity query with a language-specific condition for the moderation state field, so that the answer to the question "has the entity stored a moderation state for this language before" comes from the database, and not from the loaded entity object, some of whose fields are made-up default values.
I have not yet reported this bug, but there is a closely related bug report for the fact that the
isFirstTimeModeration()method looks at the moderation state for the latest revision of the entity, not the latest revision for the language being saved (see https://www.drupal.org/project/drupal/issues/3029219).Once all of these bugs (including the one for which this test was created) have been fixed, the test passes.
Comment #18
bklineComment #21
sam152 commentedI think this intersects with this issue enough that it should be a duplicate. Will link this one from there too.