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?

4
  • Don’t you want hook_ node_update?
    – Kevin
    Commented Jun 26, 2018 at 11:56
  • I could change to node_update, but how should I access to transition information?
    – arrubiu
    Commented Jun 26, 2018 at 11:58
  • I've edited the question
    – arrubiu
    Commented Jun 26, 2018 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
    Commented Jun 26, 2018 at 12:33

2 Answers 2

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.

2
  • 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
    Commented Jun 26, 2018 at 12:29
  • But the plumbing is there, you might be able to hook in and alter the behavior.
    – Kevin
    Commented Jun 26, 2018 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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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