1

I'm using the Rules module for sending emails. When the user adds a node, it can only be published when the admin approves it. For this I have used the content approval module.

I have made a rule which sends an email to the user when their content is published.

How do I create a rule which sends an email to the user when their content is not approved or unpublished?

  • Which is the previous state of the node before it is changed to not approved? Have you got a custom field to save this state? – jorgetutor Oct 10 '14 at 6:01
  • its unpublished. Am I supposed to change that? – newbie Oct 10 '14 at 11:02
0

hook_scheduler_api() accepts two parameters -

1. $node is the node object being processed
2. $action is either 'publish' or 'unpublish'

hook_scheduler_api()

<?php
    function yourmodule_scheduler_api($node, $action) {
  if (some condition) {
    // parameters: drupal_mail($module, $key, $to, $language, $params = array(), $from = NULL, $send = TRUE) {
    drupal_mail('yourmodule', 'mail key', $user->mail, etc depending on your needs);
  }
}
?>

hook_mail()

<?php

function yourmodule_mail($key, &$message, $params) {
  switch ($key) {
    case 'this-mail-key':
      $message['subject'] .= 'your subject';
      $message['body'][] = 'text';
      // etc ...
      break;
    // etc ...
}
?>
  • I'm kinda new to drupal. Can you please explain where I'm supposed to add that? – newbie Oct 10 '14 at 11:02
0

Here is a rule (in Rules export format) that can be used to send an email to the node author after the node is unpublished:

{ "rules_send_email_after_node_is_unpublished" : {
    "LABEL" : "Send email after node is unpublished",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_update" : [] },
    "IF" : [
      { "data_is" : { "data" : [ "node-unchanged:status" ], "value" : "1" } },
      { "data_is" : { "data" : [ "node:status" ], "value" : "0" } },
      { "NOT data_is" : {
          "data" : [ "node-unchanged:author:uid" ],
          "value" : [ "site:current-user:uid" ]
        }
      }
    ],
    "DO" : [
      { "mail" : {
          "to" : [ "node-unchanged:author:mail" ],
          "subject" : "Your content is unpublished ...",
          "message" : "This is to inform you that your node (with node id = [node-unchanged:nid] and node title = [node-unchanged:title]) has been unplublished ...",
          "language" : [ "" ]
        }
      }
    ]
  }
}

If you have the Rules UI enabled, you should be able to import the above rule in your own site.

Some more details about this rule:

  • Rules Event: After updating existing content
  • Rules Conditions (all of them must be TRUE):
    • Before the update, the node must be Published.
    • After the update, the node must be Unpublished.
    • The user performing the update must not be the author of the node (otherwise the eMail is useless, no need to send such eMail to yourself).
  • Rules Action: Send an appropriate eMail (adapt its content to fit your needs).

Obviously, you could add other Rules Conditions (eg to check the role of the user performing the update), but at its core this rule will get the job done.

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.