Problem/Motivation
When using the Fragment entities with Content Moderation there is some unexpected behaviour. The published state of the given workflow is not respected. E.g. when you save a Fragment as "Draft" the fragment is marked as published.
Steps to reproduce
- Enable workflow and content moderation modules
- Assign the Fragment type to the Workflow
- Notice that when you save a Fragment the Fragment does not match the workflow publish state
Proposed resolution
The Fragment entity is extending RevisionableContentEntityBase. However for content entities we should extend the abstract class EditorialContentEntityBase provided by Drupal core.
This will have some effect on the entity fields.
Release notes snippet: Compatiblity with content moderation
This release adds support for the core Content Moderation module. Take note that in case you previously enabled content moderation for fragments, despite the warning it is unsupported, existing fragments will not be updated to match their moderation state. One way to quickly correct the situation is is by adding the save action to the fragments administration view, selecting all fragments and applying the save action to them.
Issue fork fragments-3251840
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 #3
jaapjan commentedi think this is ready for review. What I did:
Comment #4
fonteijne commentedRTBC +1
Comment #5
fonteijne commentedDo note that existing fragments need to be re-saved to actually unpublish the fragment.
Comment #6
jaapjan commentedThis is actually a good point. We could consider writing an update hook to take care of this issue?
Comment #7
eelkeblokI am unclear what #5 means. Does this mean already unpublished fragments may become "published"? I am also a bit in the dark about the need for two mappings to the one status database column status. Sounds like this needs some more work. Feel free to set the status to RTBC again if I am misunderstanding something.
Comment #8
jaapjan commentedRegarding #5:
In Workflow you can have multiple moderation states. Each moderation state can have impact on the "status" of an entity. E.g. moderation state "Draft" will un-publish the entity. All the already saved Fragments might have a moderation state which implies that the Fragment should be unpublished, while in fact it is published. This is because this relation did not work. We have two options here: A) Re-save all the Fragments which are in a Workflow and un-publish these if necessary. B) Add a note in the release notes that the website owners who have Workflow enabled (with states that implies control over published status) for Fragments should re-save all the fragments themselves. We could add an Action that helps website owners do this.
In my opinion option A is the best but this could mean that previously published Fragments are suddenly unpublished for some websites.
Regarding the two mappings of the status:
For this I learned from Drupal Core and basically mimicked the configuration from Node.php. See the source here: https://api.drupal.org/api/drupal/core%21modules%21node%21src%21Entity%2...
I'm marking this as "Needs review" again, but if you think changes are still required to get this feature in feel free to mark as "Needs work".
Comment #9
eelkeblokAh, so the update hook really would apply only to sites where content moderation was already applied to Fragments. In that case, I think it would be better to add a snippet to the release notes explaining this and leave it there. If we were to "correct" the current situation with an update hook we might unpublish things that should not be. Better to have site owners do a manual audit, in that case.
Setting to Needs work to add a release notes snippet to the IS.
Comment #10
eelkeblokComment #11
eelkeblokComment #12
eelkeblokI added a release notes snippet to the IS. Please verify it is correct.
Comment #13
eelkeblokChanging back to the original title and to a feature request, because I just saw that content moderation nicely warns a user trying to configure it for Fragments.
Comment #14
eelkeblokComment #15
eelkeblokApplying the code changes has my instal complaining about the unknown field published. I think an update hook is in order to add it.
Comment #16
eelkeblokI also believe work is still left to do altering the entity form; revisions need to be forced to on and publishing status should not be exposed when content moderation is in use. Part of this is implementing a moderation handler (see \Drupal\content_moderation\EntityTypeInfo::addModerationToEntityType() ). The default moderation handler does nothing in that regard, the NodeModerationHandler, for example, forces revision to on and doesn't allow switching of revisions in the content type settings.
Comment #17
jaapjan commentedYes makes sense. Thank you for the feedback.
The release notes snippet looks good. Although I'm not 100% sure the "save" action will be available?
Regarding the rest of the feedback. I'll need to test this thoroughly with an existing installation and make sure the update process works as expected. Perhaps I can make some time available next week to look into this.