Problem/Motivation
When using the EntityModerationForm to change the moderation state the user can be redirected back to the canonical route for the entity, if the selected moderation state is a default revision state. Under certain circumstances I need to skip from my "approved" state straight to "published" based on field values on the entity. I can implement this logic in hook_entity_presave()
but the submit handler for EntityModerationForm performs the redirect based on the selected form value rather than what is saved in the entity. As a workaround I can attach my own submit handler, but that shouldn't be required.
Steps to reproduce
- Create 3 workflow states - draft, approved, published
- Add a custom module that implements
hook_entity_presave()
. - In the presave detect
$entity->moderation_state->value == 'approved'
and call$entity->set('moderation_state', 'published');
- Create and publish a node
- Edit the node, save as draft
- On the Latest Version tab change the status to "Approved"
- The revision should become published and you'll be left on the latest version route with a 403.
Proposed resolution
Load the workflow state for the redirect logic from the saved entity rather than from the submitted form value.
Remaining tasks
Write tests
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
N/A