Problem/Motivation
We have defined a workflow with these states:
- Draft
- Needs Review
- Published
We have two roles:
- author (Who creates content in draft and sets it to "needs review")
- admin (Who can transition from "needs review" to "published")
Steps to reproduce
- Enable the Content moderation and Content translations modules, and their requirements.
- Add another language to the site.
- Enable translation for Content (nodes) for at least one content type.
- Enable the Editorial workflow for at least one translatable content type.
- Configure the workflow with the 3 states listed above (draft, needs review, published), and 4 transitions:
- draft -> draft
- draft -> needs review
- needs review -> draft
- needs review -> published
- Configure 2 roles:
- author (with permission to use draft -> draft and draft -> needs review transitions)
- editor (with permission to use all of the above workflow transitions)
- An author has created a node in English, and sets it to "needs review".
- Now the author wants to add a translation for this node. They go to the Translate tab and click on the "Add" Button.
- The form where they can edit the node and add the german texts is displayed.
- When they click "Save", they gets the error message "Invalid state transition from Needs review to Needs review".
Logically that is correct, because the author role doesn't have the permission to edit nodes which are in the state "needs review".
But shouldn't new translations be treated as new nodes and therefore be created as "draft"?
Proposed resolution
Preserve the existing behavior for BC, but add a way to configure this when defining a workflow.
Whatever new UI is introduced should only be visible if both Content moderation and Content translation modules are enabled.
Option B
(Other rejected proposals removed, this is what we're going with).
- Have a simple toggle for the current behavior vs using the default moderation state (same as A)
- UI is 2 radios.
- Setting stores a string, ID would be 'translation_default_moderation_state_behavior' or so, with values like 'current' vs. 'default'.
- In some UIs, explicit radios for different options can be more clear than a checkbox (if each choice requires a little explanation).
Example UI:
Initial moderation state when adding a new translation:
(*) Default moderation state
( ) Current moderation state of the original content
Open questions
Which UI is best for the setting?Option B - radio buttons. See #45Since all the code handles no value for this setting as if you want the current behavior, do we need an upgrade path and all that complication?Yes (@larowlan in #42)Do we want to add this setting to the default workflows shipped with core?YEScore/profiles/standard/config/optional/workflows.workflow.editorial.yml? YESIf so, should we set it to 'default' or 'current'?Using 'current' per @larowlan in #42Also demo_umami?YES
Does this issue need a CR?YES: https://www.drupal.org/node/3240957Do we need more test coverage?YES:Should the #default_value for these radios use 'default' for new workflows? It's now defaulting to 'current' if missing from the config for BC on existing sites. But presumably we could notice when creating a new workflow and use a different #default_value to be the more intuitive 'default'.NO, leave it as 'current' (per @larowlan in #42).Where is the right layer of the entity / translation / content_moderation systems to specify the default moderation state of a new translation? See comment #33. We don't want to have to rely on field widgets to enforce this setting. It'd be better if we directly changed the moderation_state when populating a new translation so that field widgets don't need to support this setting, and so it works if there is no widget for moderation_state. Should we?- Use
hook_entity_translation_create()
YES. Directly hackNOEntityOperations::updateOrCreateFromEntity()
? This seems problematic since we'll have a hard time knowing if the entity has a value from a widget or if its own override logic should kick-in.Other?
- Use
What should the UI help text say for the "Legacy" config option?See #101.
Remaining tasks
Answer the open questions.Implement the new setting / UI.Don't check if the user has access to this transition (because it should be treated as new).Add a DB update for existing sitesAdd tests:What you see when creating a new translation (the bug)The two different roles case described in the summary.Done in #47The upgrade pathThe UI for this when creating a workflow.Done in #47.
Decide what to do that the legacy behavior is not "Current moderation state of the original content" as the UI suggests, but actually a hardcoded choice between exactly 'published' (if the original content is currently in any published state) or 'draft' (for any unpublished current state). See #91UX team proposed a solution in #101, implemented in #104- RTBC
User interface changes
A new setting when creating/editing a workflow:
Before
What you see without the patch applied, or when content_moderation is enabled but content_translation is not, at paths like /admin/config/workflow/workflows/manage/editorial:
After
With the patch applied, and both content_moderation and content_translation enabled:
Initial moderation state when translating existing content*
(*) Default moderation state
( ) Published if existing content is published, otherwise Draft
API changes
None.
Data model changes
New config schema for a setting on workflow type plugins.
Release notes snippet
TBD.