I have been tracking a bug in our implementation of Content Moderation which has brought me to ask whether we are doing it in the right way or if this is an unconsidered edge case to Content Moderation API? Should moderation_state be avoided in presave? Is there a formal Content Moderation State API method to universally set state?

Given:
1. Entity Content Moderation workflow initial state is called "Draft"
1. Entity is in non-initial state (ie. not "Draft")
1. Entity presave sets (overrides) moderation_state to another non-initial state (ie. Advances it in workflow given some conditions are met)

When:
1. User sets the state to "Draft" in the entity edit form and hits Save
1. Entity enters presave, and presave programmatically sets (overrides) moderation_state
1. Entity save completes

Expected:
New Entity revision_id corresponding to new moderation state only.

Instead:
* Intermediary revision_id corresponding to new Draft pre-presave AND second, new revision_id corresponding to presave-set moderation state.
* The tables `content_moderation_state_field_revision` and `content_moderation_state_field_data` lack any knowledge of that phantom intermediate revision_id (9494 in my screenshots).
* The phantom revision nonetheless appears in the Revisions tab and happens to show the desired Draft state due to #2848089: Unable to set a moderation_state value for unsaved entities that are assigned an ID..

See screenshots.

Comments

texas-bronius created an issue. See original summary.

sam152’s picture

Status: Active » Postponed (maintainer needs more info)

Is there a way to reproduce this issue in a test case or provide a minimal code sample that reproduces the problem in a fresh install? I can't think of why updating entity field values in preSave would create two revisions where only one is expected. Do you know if that is caused by content moderation or is some other code path triggering the save twice?

texas-bronius’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

Thanks @Sam152 - It has been a while since I've looked at this specifically, and I have additional features in my instance like translation and some patches here and there to mediate revision + translation. I will get this out of your radar (closed - can't reproduce) unless and until I can provide more clarity.

As for my own head of hair, your acknowledgement that "yes there should be no problem here" is a great response for me :) so I know where else to look.