Notify in Drupal using actions and triggers

Submitted by Nicola Rainiero on 2012-08-30 (last updated on 2015-06-14)

Setting up actions and triggers and using tokens, it is possible to create an efficient method that inform by email the admin, after anonymous user inserts a new comment awaiting approval. Besides it notifies the anonymous of the approval of one's message and any replies, if has left email, as highlighted in the form, overriding the standard strings of Drupal.

In these last days and through a profitable discussion here, I was going to test the possibilities offered by Drupal to send notification. I began from extra modules, installing the two following ones:

Really it exists an useful quick review table that confront 5 Drupal modules to comment notifications in Drupal, but I discovered it later, and it is available at this wiki page: Comment Notifications. From this comparison and my little experience (I tried them in a private installation of Drupal), the best is Comment Notify, but I wasn't be able to activate it for anonymous users!

Well, my real target was another one: I wanted to understand and use the triple alliance: actions/triggers/tokens. I had already installed them in my Drupal configuration (the first two are present in the core), and token is a module very useful and needed by pathauto. This last one is a module that "provides a user interface for the Token API and some missing core tokens", for example in this article I use it to identifies automatically: user's email, title and body of comment, etc. In the following image you can see some of them in the bottom of the actions page:

Example of tokens used for comments

 Requirements^

  • Install token module as announced above;
  • Go in http://my_site/admin/structure/types and for desiderable content types (Article, Blog, etc.) enable Threading and Anonymous posters may leave their contact information in Edit --> Comment settings as showed in the picture:

Comment settings to permit anonymous leave their contact information

 Actions^

I created three advanced actions in http://my_site/admin/config/system/actions and clicking Choose an advanced action --> Send e-mail... --> Create with these data:

  1. First action:
    • Label --> Send e-mail to admin
    • Recipient --> [email protected]_site.it (I had to put my real email because all tokens used didn't work) [site:mail]
    • Subject --> Comment awaiting approval on [site:name]
    • Message -->
      ### New comment on post: [comment:node] ###
      [comment:mail]
      [comment:author]
      [comment:hostname]
      -------------------------------------------------------------
      [comment:title]
      [comment:body]
      -------------------------------------------------------------
      
      Link: [comment:url]
    • Save
  2. Second action:
    • Label --> Send e-mail to anonymous user (pubblication)
    • Recipient --> [comment:mail] [comment:original:mail]
    • Subject --> Your comment has been approved by [site:name]
    • Message -->
      Hello [comment:author],
      
      Your comment:
      -------------------------------------------------
      [comment:title]
      [comment:body]
      -------------------------------------------------
      
      Is available on Post [comment:node:title] at: [site:url]/node/[comment:node:nid]#comment-[comment:cid]
    • Save
  3. Third azione:
    • Label --> Send e-mail to anonymous user (reply)
    • Recipient --> [comment:parent:mail]
    • Subject --> New reply to your comment in [site:name]
    • Message -->
      Hello [comment:parent:author],
      
      New reply to your comment here:
      [comment:url]
              
    • Salva

 Triggers^

From this page http://my_site/admin/structure/trigger/node, click on COMMENT in the upper right menu and then define these triggers:

  • Trigger: After saving a new comment --> Send e-mail to admin
  • Trigger: After saving an updated comment --> Send e-mail to anonymous user (pubblication) and Send e-mail to anonymous user (reply)

 Strings overrides^

In order to inform the anonymous that if he/she inserts own's e-mail, my site will notify by email the pubblication and any replies to its comment, I follow two ways:

  1. changing the default translate interface (if you use a multilanguage site)
  2. overrrides the built-in interface

Translations into Italian

  • Enter here http://my_site/admin/config/regional/translate/translate;
  • write in String contains form, some words of the wanted string and click enter key;
  • choose the result in English (remember the exact and entire phrase, because you will use it in the next section);
  • click on edit and change the text, then save.

In my case:

Il contenuto di questo campo è privato e facoltativo, non verrà mostrato pubblicamente. > Il contenuto di questo campo è privato e facoltativo, non verrà mostrato pubblicamente.<br /> <strong>Se inserito verranno notificate la pubblicazione del commento e le successive risposte</strong>.
I commenti verranno accodati per una revisione dell'amministratore e saranno pubblicati dopo l'approvazione. > I commenti verranno accodati per una revisione dell'amministratore e saranno pubblicati dopo l'approvazione. Se in fase di compilazione è stata inserita anche la propria email, l'avvenuta pubblicazione e le eventuali risposte verranno notificate.

Overrrides the built-in interface

The correct way is to add some custom strings to settings.php in http://my_site/files/default/ below String overrides section:

/**
 * String overrides:
 *
 * To override specific strings on your site with or without enabling locale
 * module, add an entry to this list. This functionality allows you to change
 * a small number of your site's default English language interface strings.
 *
 * Remove the leading hash signs to enable.
 */
# $conf['locale_custom_strings_en'][''] = array(
#   'forum'      => 'Discussion board',
#   '@count min' => '@count minutes',
# );
$conf['locale_custom_strings_en'][''] = array(
   'The content of this field is kept private and will not be shown publicly.' => 'The content of this field is kept private and optional, will not be shown publicly.<br /><strong>If you insert it, the site will send you a notify after publication of this one and any replies</strong>.',
   'Your comment has been queued for review by site administrators and will be published after approval.'      => 'Your comment has been queued for review by site administrators and will be published after approval. If you have defined your email address, the site will send you a notify after approval of this one and any replies.',
);

 


 References^




Related Content:

Nicola Rainiero

A civil geotechnical engineer with the ambition to facilitate own work with free software for a knowledge and collective sharing. Also, I deal with green energy and in particular shallow geothermal energy. I have always been involved in web design and 3D modelling.

Comments

Add new comment

The content of this field is kept private and will not be shown publicly.

Plain text

  • No HTML tags allowed.
  • Web page addresses and email addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.