Using the new Actions and Triggers functions in Drupal 6

Last modified: October 21, 2008 - 11:52

This is the companion handbook page for the Drupal screencast Drupal 6: Actions and Triggers (torrent). It contains an outline of what is in the video, slides as images and the text in the video.

In the video

  1. What is a trigger?
  2. What is an action?
  3. How do I enable triggers? (slide)
  4. How do I enable triggers? (demo)
  5. What can I do with actions and triggers?
  6. Example 1 (slide)
  7. Example 1 (demo)
  8. Example 2 (slide)
  9. Example 2 (demo)
  10. Example 3 (slide)
  11. Example 3 (demo)
  12. Ending notice

What is a trigger?

Triggers are Drupal events such as saving or updating a post, a user logging in or someone viewing a piece of content. Think of it like a trigger for an argument – when the trigger happens (ie. A disagreement), an Action happens (the argument). This allows you to heavily customize Drupal and paves the way to amazing new implementations of the software.

What is an action?

Actions are something that happens after the trigger. For example, you could redirect the user to a page, send an email notice to administrators or display a special message. This can allow you to integrate Drupal into other systems.

How do I enable triggers? (slide)

To begin using Triggers and Actions, you first must enable the Triggers Module included in Drupal 6.0. Follow the following instructions:

How do I enable triggers? (demo)

  1. Login to your Drupal administration panel
  2. Go to the Administer page
  3. Select the Modules section
  4. Scroll down the page to "Triggers" on the list. Tick the box adjacent to it and then click "Save configuration" at the bottom
  5. Return to the administer page - a Triggers option should have appeared.

What can I do with actions and triggers?

Actions and Triggers are pretty awesome really. They give you the ability to add some extra dynamic features to your Drupal installation without any coding or real technical knowledge.

It’s like writing a new Module for Drupal, but easier. The best thing is that there are so many things you can do! Here are some real world example of things you could do using Actions and Triggers:

Example 1 - auto-promote to front page (slide)

Ever written a piece of content and forgotten to Promote it to Front Page? It sounds simple, but it gets annoying if you have to go and promote it manually. Using the "After saving a new post" trigger and the "Promote Post to Front Page" action, you can make this happen automagically!

Example 1 - auto-promote to front page (demo)

  1. Login and go to the administer page as before
  2. Go to the "Actions" page - we need to make the "Promote to front page action"
  3. Scroll down to the list of actions - as you can see, there is already a "node" type action called "Promote Post to Front Page". Drupal comes with some predefined actions which will often be helpful. We don't need to customize it in this case. However, look down and be aware of the customizable actions in the drop down menu.
  4. Go back to the administer page and then go to "Triggers".
  5. Look at the top - there are five types of trigger. Each (current) trigger will be categorised under one of these types. We want the content section, which is shown automatically. We want stories to be automatically promoted when they're created or edited, so we will use the "When either saving a new post or updating an existing post" trigger. Go to the drop down menu below the title, and then select the "Promote post to front page option" and then click Assign.
  6. Navigate away and post some content. Once you've written it, open the Publishing section and tell it not to Promote it to Front Page. Click Save, and it will be promoted to the front page anyway! Your action and trigger set is working!

Example 2 - alert writer to a new comment (slide)

Don’t you just love that warm, fuzzy feeling when you get a comment on something you’ve written? It’s really nice to be appreciated for your hard work. You can get an alert when someone comments on your story using the “After saving a new comment” trigger with the “Send an email” action. In this set, you will be using variables.

Example 2 - alert writer to a new comment (demo)

  1. Go to the Administer page, and then go into the "Actions" section. Scroll down - we will be using a customized option this time.
  2. In the menu, select "Send e-mail..." and then click "Create".
  3. A new page will appear for you to customize it. Make sure you use a description so you can recognise what one it is - before long you'll have loads of different actions!
  4. Look at the "Recipient" field. Below it says that you can put "%author" in the field to send the email to the author of the post, which is what we want to do! Type "%author" into the field.
  5. Set a subject of your choice and then put a message into the final field - for example, you could put "You've got a new comment on your story - go take a look!". Finally, click Save.
  6. You will return to the Actions page. Scroll down to see your new action. Head back to the "Administer" page now.
  7. Go to the "Triggers" page, as we now need a trigger.
  8. This one is in the "Comments" tab, as opposed to the comment tab. Click "Comments" near the top.
  9. We need the "After saving a new comment" trigger - go to the drop down box in it and then select the Action that you made earlier. Click "Assign".
  10. It's done! Now you will receive an email if someone comments on your post!

Example 3 - personalized member welcome (slide)

Is your site a bit of a niche site with a dedicated fan-base or do you want to really make your customers feel at home? You can get notified when a new member joins so that you can send a customized notice to them personally! Use the “Send email” action with the “After a user account has been created” trigger.

Example 3 - personalized member welcome (demo)

  1. Go to your "Administer" page and then go to Actions.
  2. Once again, we need to use the "Send e-mail..." action but this time with the "After a user account has been created" trigger. Scroll down, and then create a "Send e-mail" action.
  3. In the Recipient box type your email. Give it a memorable description, in the Subject put something like "New member has joined" and in the message put something like "A new member has joined, remember to email them!". Click "Save".
  4. Go to the "Triggers" page now - you can use the link at the top of the "Actions" page.
  5. For this one, you need to use the "Users" tab. Click on "Users".
  6. Scroll down to the "After a user account has been created" trigger and then in the drop down box select the Action that you just created and then click Assign.
  7. You will now receive an email when a new member joins.

Ending notice

Thank you for watching the Drupal screencast on Actions and Triggers. I hope that this has been useful, and has helped you to understand the new options and use them effectively to improve your site. Visit the handbook page on Actions and Triggers for a text only version of the screencast.

Torrent link not working

juliendorra - May 1, 2008 - 22:34

Te current link to the torrent don't seems to work (anymore ?).

Use this one instead :

http://google-highly-open-participation-drupal.googlecode.com/issues/att...

Create an Action for a Trigger

Wolfflow - June 12, 2008 - 05:14

How do I create an Action for a Trigger
if there is no similar action listed for it?

example:

I want that after login a user-role goes directly to a published node that is not
frontpage but a specific one.

Ok: I have found that you have to do following for creating the action:

Go to home --> Administer --> Site Configuration --> Action

1. Go down the page and select: Chose an advanced action
2. Select the exitent Redirect to URL Action
3. Click on Create
4. input your URL, in form node/(the number of your node) or a complete URL
if you need to (i.e. if you want to redirect your user to another Drupal-site)
5. Save

Go to home --> Administer --> Site Configuration --> Triggers
there you will find that on top you have following buttons:
[Comments] - [Content] - [Cron] - [Taxonomy] - [User]

1. Select the [User] Button
2. Select the Trigger: After a user has logged in
3. With the dropdown field select: the Action you have create above.

That is it, enjoy

Share your experience with the Open Source Community
it's not only a choice but a Life Philosophy !!!
http://www.adaccs.at A CSS Documetation Project

own admin comment notification, disable ?

wwwoliondorcom - August 27, 2008 - 08:54

Hi,

When using actions and triggers on Drupal 6 I (the admin) get an email notification even when I post a comment with the admin user account, do you know how to disable this ? I don't want to be notified of my own comments.

Thanks a lot.

trigger, action and filter

twlintw - August 29, 2008 - 09:26

i tried setting a content filter to censor some text, somehow when i set a action on "when saving a new post", the original text still get sent, is there anyway that i can by pass the the trigger before applying the filter to text?

 
 

Drupal is a registered trademark of Dries Buytaert.