Last updated September 21, 2009. Created on December 9, 2007.
Edited by xurizaemon, Rowanw, LeeHunter, TimRogersCool. Log in to edit this page.

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 "Trigger" 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.

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

juliendorra’s picture

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...

Wolfflow’s picture

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

Learning for Module Developer Status

wwwoliondorcom’s picture

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.

twlintw’s picture

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?

Wolfflow’s picture

Commonly the function to notify the admin of a Drupal Site is very worth fully for the Admin Role, as it is the responsibility of the Admin(Site Webmaster) to have an overview of all what happen on the Site.

The best and most used procedure is to have two different accounts for who is the Owner of a Drupal Site. This means you are best off when you create an account for Yourself out of the "Supe-User" account (That one that after the default Drupal installation has automatically all permissions).

If you do not like to find admins-alerts emails from your Drupal Site, why you do not make a filter in your mailbox so that all Drupal Site Admins Alerts goes in a specified mail-sub-folder?

In this way you may have always the possibility to have the choice, when you want to check to see all Drupal admins alerts without being bother in your inbox

Hope you decide to accept this suggestion because Drupal-Admins-Alerts can safe you a lot of time!

Best Regards

Learning for Module Developer Status

Jamer’s picture

I have forum and what I need to do is as someone replys to a post i want this promoted to the front page, (sort of a bump) I think i have set up a trigger, i have gone through some older messages and replied to one to test it, and nothing?? my post is there but it has not appeared on the front page as i was expecting?? am i doing something wrong? any advice appreciated

Fataneh’s picture

hi,i want triggers for every person who put comment for each post and every time that every person reply to that,sen email for every user.
for example:
i create a new post and a person put comments for it,after that send an email for me and his/her also every person put comment for that post,send email for all of us.
how does it work?

mattwmc’s picture

Is there any way to set up a trigger that when a specific user role creates a new node the admin can be e-mailed?

I made the option to e-mail when creating or editing a post - but I just want it for a specific user role (Staff Writer).

Thanks!

Maung Maung’s picture

We can use Rules module for this case.

By using Rules, we can extend core trigger and actions to get dynamic functionalities based on user activities, roles, nodes and comments. It is really awesome.

If you can't figure out how to use Rules in this case, let me know. Hopefully I can help.

Best Regards

Life is too short, love it, be happy, don't waste your time with sorrow, anger and upsets. :)
Drupal and web knowledge sharing, Personalize Drupal training in Singapore

Maung Maung’s picture

It is easy to do with Comment Notify module.

Life is too short, love it, be happy, don't waste your time with sorrow, anger and upsets. :)
Drupal and web knowledge sharing, Personalize Drupal training in Singapore

Maung Maung’s picture

It is easy to do with Comment Notify module.

Life is too short, love it, be happy, don't waste your time with sorrow, anger and upsets. :)
Drupal and web knowledge sharing, Personalize Drupal training in Singapore

bobburns’s picture

user warning: Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '=' query: SELECT h.aid, a.description FROM trigger_assignments h LEFT JOIN actions a on a.aid = h.aid WHERE h.hook = 'apply_for_role' AND h.op = 'apply' ORDER BY h.weight in /home/prosthet/public_html/modules/trigger/trigger.admin.inc on line 279.

is what i get when I enable trigger and assign a function to trigger on. It shows on the home page when logged out too - so I had to disable it again, but says this below:

user warning: Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation '=' query: SELECT aa.aid, a.type FROM trigger_assignments aa LEFT JOIN actions a ON aa.aid = a.aid WHERE aa.hook = 'nodeapi' AND aa.op = 'view' ORDER BY weight in /home/prosthet/public_html/modules/trigger/trigger.module on line 147.

Has this been seen before and is there a patch or workaround?

bob

EDIT

Apparently another user ran into the same thing. It appears to be due to a Fantasico installation that does a utf8_general database setup for Drupal; and then modules that use the unicode format later. I will need to pull my data down - delete the database; create a new database in utf8_unicode format and repopulate the data in the unicode format database.

My question now is:
1. Is there a shortcut to this; and/or
2. Will the utf8_general format come right back with the data or corrupt the new database?

ayathullah’s picture

Hi,

I'm using the twitter module for my site and getting errors when I enter tokens in the actions field for the twitter username.

How do you set up a rule to post a message to the current user's Twitter account? At the moment, the form in the "Post a message to Twitter" action only permits a absolute value. I want to use a token for the current user's Twitter account.

Perhaps someone can give me a code snippet that I can implement either to the twitter module or to the tokens module- to pull the logged in users twitter account username.

Thanks,
ayathullah

dougthelegoman’s picture

The video was super-helpful!