Closed (outdated)
Project:
Drupal core
Version:
10.0.x-dev
Component:
content_moderation.module
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
9 Oct 2017 at 13:28 UTC
Updated:
28 Jan 2021 at 21:14 UTC
Jump to comment: Most recent
Comments
Comment #2
timmillwoodI'm not sure I understand the issue?
Comment #3
sam152 commentedYou might need some of the code in #2873287: Dispatch events for changing content moderation states. It loads what the previous status was for the event it dispatches. Word of caution, the
content_moderation_stateis@internal, so you might experience API breaks in the future implementinghook_entity_presave.Comment #4
johnwebdev commentedI did a work around and stored the current moderation state in the $form_state object on a Node form alter.
And then in my custom submission handler I had the correct values. Perhaps you could also attach your submit handler before Moderation State ones, but I didn't bother.
Obviously this would only work if the only way to update a entity state is on its form.
Comment #5
dabbor commentedI've observed the same problem when using
hook_entity_update().The documentation for
hook_entity_update()https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21... says:and as the Content Moderation module is a core module (Workflows as well) I would not expect that using Content Moderation for a node is going to break the original entity in the
$entity->original. I checked it and the original entity is not the original entity we've just updated, but the "Current revision" instead, meaning the latest published revision (you can find it on the page/node/[nid]/revisionsmarked as "Current revision"). It may be a problem/bug with revisions in general.So as a result the
$entity->originalis not what the documentation says, but the "Current revision" instead. I consider it as a bug as we are getting something else than what is expected (documented) and it is caused by a core module "Content moderation" or Revisioning in core and not by some contrib module. I believe that core modules needs to play nice with the other core modules and the Drupal core itself.I've tested the value of "moderation_state" in
$entity->originaland it contains the previous state just fine till the node reaches the "Published" moderation state. Coming back from that state to "Draft" and then to "Needs Review", the "moderation_state" in$entity->originalis always "Published" (because of the wrong$entity->originalvalue).I've had to use the workaround with
hook_entity_presave()similar to the comment https://www.drupal.org/project/drupal/issues/2914901#comment-12413964 (#4). That workaround is nicely used by thecontent_moderation_notificationscontrib module https://www.drupal.org/project/content_moderation_notifications and the issue https://www.drupal.org/project/drupal/issues/2873287, as mentioned above, was helpful.Comment #6
sam152 commentedI agree, this is probably a bug or at the very least quite confusing. I'm sure it has something to do with the nature of the computed field loading the state on demand. It also doesn't help that the point/behaviour/semantics of
$entity->originalare kind of ambiguously defined and not a huge focus in testing.The fact that it's a public property with no documented method/interface would make me inclined to steer away from using it wherever possible.
Comment #7
marcoscanoCame across this as well. I guess #2833084: $entity->original doesn't adequately address intentions when saving a revision and #2859042: Impossible to update an entity revision if the field value you are updating matches the default revision. might be related.
Comment #8
sam152 commentedGetting the original state of an entity is being added in #2914873: The "from state" used for calculating available transitions is changed when using the content moderation state widget and preview mode.
Comment #9
smustgrave commented#5 thank you for pointing to a contrib module that got it working! Anyone know if $entity->original will ever hold the previous moderation state? Or should how content_moderation_notification did it should that be added to core?