The Drupal 6 Trigger module adds
actions to be fired on certain system events, such as when new content is created. What is that in English? You can tell Drupal to do extra stuff for you. When a visitor adds a comment to a page on your Website, you can tell Drupal to send you an email containing the comment. That saves you looking in the comment queue to see what is new. This page shows you exactly how to do it.
This page is based on Trigger in Drupal 6.15. There are a lot of things you can do with Trigger. Try the following example then experiment with other options.
A trigger starts an action when certain conditions occur. The trigger contains the Who, What, When, Why, and the action contains the How.
Switch on the Trigger module supplied in the standard Drupal download. Go to Administer » Site building » Modules. Switch on Trigger. Then go to Administer » Site building » Triggers to set up triggers. You can set up triggers for Comments, Content, Cron, Taxonomy, or Users.
While you are in the modules list, switch on Token actions. Token actions is supplied with the Token module. Token actions
Provides enhanced versions of core Drupal actions using the Token module. Token actions adds a tokenised email action option after the existing email action and the tokenised version has a wider variety of substitution tokens.
The Token module provides a token service to other modules. You probably have Token installed because another module asked for Token. Drupal 7 includes Token as a standard part of the Drupal core. Triggers will almost certainly switch to using Token in Drupal 7. You might as well start with Token in Drupal 6.
Go to Administer » Site building » Triggers then select the Comments tab. You are now at
Your choices are:
- Trigger: After saving a new comment
- Trigger: After saving an updated comment
- Trigger: After deleting a comment
- Trigger: When a comment is being viewed by an authenticated user. No available actions for this trigger.
Each trigger has a list of actions similar to the following.
- Unpublish comment
- Publish post
- Unpublish post
- Make post sticky
- Make post unsticky
- Promote post to front page
- Remove post from front page
- Save post
There is no send email action by default. You have to create your own action. Go to Administer » Site configuration » Actions to create actions.
Go to the Make a new advanced action available selection, select Send e-mail..., then select Create.
Change the Description to Send e-mail to admin, Recipient to your email address, firstname.lastname@example.org, give the email a Subject, You got comment!, then a message. The message can contain substitution variables including %site_name, %username, %node_url, %node_type, %title, %teaser, and %body. The following message would be a good starting point for comments.
%username sent a comment from %site_name about %title. The comment is:
There is just one problem. %body sends the body of the page, not the body of the comment. Time to use Token actions.
The Token actions module adds the following choices to Make a new advanced action available. The tokenised email offers more choices.
- Display a tokenized message to the user...
- Send tokenized e-mail...
- Redirect to a tokenized URL...
If you use Send tokenized e-mail..., you could use the following message.
[comment-author-name] sent a comment from [site-name] about [title]. The comment is:
If you use the token version of the email, you could also use tokens in the subject.
Comment on [title]
The Trigger module provides easy control of useful actions in Drupal 6. For our example, we need the tokenised actions from the optional Token actions module.