Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 294806

EntityModerationForm redirect doesn't allow for moderation state changes in entity presave hooks

$
0
0

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

  1. Create 3 workflow states - draft, approved, published
  2. Add a custom module that implements hook_entity_presave().
  3. In the presave detect $entity->moderation_state->value == 'approved' and call $entity->set('moderation_state', 'published');
  4. Create and publish a node
  5. Edit the node, save as draft
  6. On the Latest Version tab change the status to "Approved"
  7. 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


Viewing all articles
Browse latest Browse all 294806

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>