0

I've a content type with a workflow. I have to notify users when the published version of the node is update.

Have I to check which transition is used? How?

I'm using an hook_node_presave.

[EDIT] It seems that check if it's the default revision could be right:

 $entity->isDefaultRevision();

From draft to draft is false. From draft to published is true. From published to published is true.

Could be the right way?

  • Don’t you want hook_ node_update? – Kevin Jun 26 '18 at 11:56
  • I could change to node_update, but how should I access to transition information? – arrubiu Jun 26 '18 at 11:58
  • I've edited the question – arrubiu Jun 26 '18 at 12:06
  • However: this method returns true also with transition from "published" to "archived". The way is how to check which transition is performed – arrubiu Jun 26 '18 at 12:33
0

As an alternative, consider using the Content moderation notifications module:

Allows notifications to be sent to all users of a particular role, or to the content's author when a piece of content is transitioned from one state to another via core's content_moderation module.

I've used it with good results in several sites.

  • I see it, but I've to notify all users that have edited the node (with a loop on all the revisions). I could use that module with an hook.. – arrubiu Jun 26 '18 at 12:29
  • But the plumbing is there, you might be able to hook in and alter the behavior. – Kevin Jun 26 '18 at 13:11
0

You can simply get the Moderation state of node in the hook_node_presave(). like below:

$node->get('moderation_state')->getString()

It will give you the string like publish or unpublish.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.