Problem/Motivation
When cloning a node which is under content moderation the status is not cloned. It is set to the default status of the workflow. Clone publication status of original? does not change this.
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | 3273337 after.png | 274.09 KB | csakiistvan |
| #8 | 3273337 settings.png | 249.36 KB | csakiistvan |
| #8 | 3273337 before.png | 1023.14 KB | csakiistvan |
| #3 | 3273337-3.patch | 3.89 KB | jurgenr |
| #2 | 3273337-1.patch | 3.94 KB | jurgenr |
Issue fork quick_node_clone-3273337
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
jurgenr commentedI'va added a patch that handles workflow management.
The behaviour is added on the original node in the form, and all translations in the QuickNodeCloneEntityFormBuilder().
Comment #3
jurgenr commentedUpdated patch to use unpublished status instead of draft.
Comment #6
liam morlandI have created a merge request with the patch in #3.
Comment #7
csakiistvanComment #8
csakiistvanEnvironment
Prerequisites
quick_node_clone,content_moderationandworkflows.editorialworkflow (/admin/config/workflow/workflows/manage/editorial). The workflow provides the states Draft, Published and Archived — there is no Unpublished state./admin/config/quick-node-cloneand set Clone publication status to Clone publication status of original.Steps
QuickNodeCloneEntityFormBuilder::getForm(), pass it to the form through the form state, and preselect it on the widget inquick_node_clone_form_alter().ddev drush cr/clone/<nid>/quick_cloneand look at Save as at the bottom of the form.Expected results
Actual results
The bug is reproducible on 8.x-1.22: with Clone publication status of original and a published, moderated article, the clone form shows Save as: Draft instead of Published. The root cause is that
ModerationStateWidget::formElement()resets the moderation state of unsaved entities to the initial state of the workflow, so any state set on the clone inQuickNodeCloneEntityFormBuilder::getForm()is discarded before the widget is built.The first revision of MR !68 only fixed the Published setting: the
originalcase stayed a no-op, and the Unpublished and Use the default status of the content type settings wrote values into the widget that are not moderation states (the stringunpublished, which no core workflow defines, and the boolean bundle default). The MR was reworked accordingly — the wanted state is now passed through the form state so it survives the widget, theoriginalcase takes the state of the original node, and the target state is resolved from the workflow (initial state first, otherwise the first state with the wanted publication status) instead of being hard coded.After the rework all four settings behave as expected on a published moderated article (Published for original, published and default, Draft for unpublished), a draft original is cloned as Draft with the original setting, and cloning an unmoderated content type is unchanged.
phpcswith theDrupalandDrupalPracticestandards is clean on the changed files.Changes
src/Entity/QuickNodeCloneEntityFormBuilder.php— theclone_statusswitch now goes throughsetCloneStatus(), which sets a moderation state on moderated nodes and keepssetPublished()/setUnpublished()for everything else, because content moderation derives the publication status from the state and would overwrite the status field.getModerationStateId()resolves the state from the workflow (initial state first, otherwise the first state with the wanted publication status), so no state ID is hard coded and workflows without apublishedorunpublishedstate keep working. The resulting state is passed to the form in$form_state_additions['quick_node_clone_moderation_state'], since the widget discards the state set on the entity. Theoriginalcase takes the state of the original node instead of doing nothing — this is the case reported in the issue summary.quick_node_clone.module—quick_node_clone_form_alter()preselects that state on the moderation state widget, but only if it is among the transitions available to the current user, so the form never offers a state the user may not select.quick_node_clone.services.yml—content_moderation.moderation_informationis injected as an optional dependency (@?), so the module keeps working when content moderation is not installed.Remaining work
.gitlab-ci.ymlchange (OPT_IN_TEST_NEXT_MAJOR: 1→0) is unrelated to the fix and should be dropped.Testing produced with the assistance of an LLM.