-
Notifications
You must be signed in to change notification settings - Fork 10
Rules Core
The Rules module allows site administrators to define conditionally executed actions based on occurring event conditions. You can read more about this topic at Wikipedia's ECA-rules article). This can be a complicated subject at first, but the most important take away message going into it is that Rules opens opportunities for site builders and developers to extend Drupal in ways not possible before.
Rules allows you to configure actions to be fired on various events. For example, if a user is creating a new content, the event "Content has been created" occurs. So Rules allows you to react to this event by firing actions. There are a lot of different events available, and contributed modules can even introduce new events.
Events supported by default:
Event | D6 | D7 | D8 |
---|---|---|---|
Comment | |||
After deleting a comment | ✔ | ✔ | ✔ |
After publishing a comment | ✔ | ✔ | tbc |
After saving a new comment | ✔ | ✔ | ✔ |
After saving an updated comment | ✔ | ✔ | ✔ |
After unpublishing a comment | ✔ | x | tbc |
Comment is being viewed | ✔ | ✔ | ✔ |
Before saving a comment | x | ✔ | ✔ |
Nodes | |||
After deleting content | ✔ | ✔ | ✔ |
After saving new content | ✔ | ✔ | ✔ |
After updating existing content | ✔ | ✔ | ✔ |
Content is going to be saved | ✔ | ✔ | ✔ |
Content is going to be viewed | ✔ | ✔ | ✔ |
System | |||
Cron maintenance tasks are performed | ✔ | ✔ | ✔ |
User is going to view a page | ✔ | x | tbc |
Drupal is initializing | ✔ | ✔ | ✔ |
System log entry is created | x | ✔ | ✔ |
Taxonomy (if enabled) | |||
After saving a new term | ✔ | ✔ | ✔ |
After updating a term | ✔ | ✔ | ✔ |
After deleting a term | x | ✔ | ✔ |
Before saving a term | x | ✔ | ✔ |
After deleting a vocabulary | x | ✔ | tbc |
After saving a new vocabulary | x | ✔ | tbc |
After updating an existing vocabulary | x | ✔ | tbc |
Before saving a vocabulary | x | ✔ | tbc |
User | |||
User account details have been updated | ✔ | ✔ | ✔ |
User account has been created | ✔ | ✔ | ✔ |
User has been deleted | ✔ | ✔ | ✔ |
User has logged in | ✔ | ✔ | ✔ |
User has logged out | ✔ | ✔ | ✔ |
User page has been viewed | ✔ | ✔ | ✔ |
Before saving a user account | x | ✔ | ✔ |
Rules events have nothing to do with calendars. ;)
Rules provides various actions, which let you actually do something. Some examples of actions are
- send an email to a user
- unpublish content
- delete a comment
- ...
So the combination of Events and Actions could read like any of these examples:
- When "a user has logged in", "send an email to a user".
- When "content has been viewed", "unpublish content".
Some actions can be configured (eg. what email address to use when sending mails), and some need no configuration (unpublish content). Some simple and configurable actions are provided by the Rules module, and contributed modules may provide further actions.
So let's have a look at how actions & events play together:
This is an example, that shows how Rules is firing actions. It shows an action, which is configured to be fired on the event "Content has been updated".
Note that there are two different kind of actions: First off there are "drupal core actions", compatible with the trigger module and also with the Rules module. Then there are Rules-compatible actions, that can be only used with the Rules module, and these are a bit more powerful.
Conditionals allow you to configure actions so that they are only executed if the configured conditions are met.
Again, let's have a look at how conditions interact with actions and events:
Here the action is only fired if the content author is different than the acting user and so the condition evaluates to TRUE.
Like actions, Rules provides some configurable conditions and contributed modules may provide further conditions. Rules also supports negating conditions as well as the concept of condition groups, which are logical operations like OR and AND.