2. The Rules module allows site
administrators to define
conditionally executed actions
based on occurring events
(known as reactive or ECA
rules). It's a replacement with
more features for the trigger
module in core and the
successor of the Drupal 5
workflow-ng module.
What is Rules
4. Rule structure
Condition – in which cases it should react
Action - what should happen?
Events – system events(s) to which one(s) rules will react
5. Rules Components
●
Reusable part of Rules
●
Condition set (OR/AND), action set, rule, rule set
●
Components evaluation can be scheduled
●
Can be imported
●
Can executed (good for debugging)
6. Rules Scheduler
●
Rules Scheduler needs components – you can only schedule prepared components
●
Components can be scheduled as actions, for example from reaction rules
●
The evaluation time for scheduled tasks is set with strtotime(), which means that you can use highly
flexible expressions
●
You can also use data selection, combined with offsets if you want to
●
Every scheduled task should have a unique task ID, or it will replace existing tasks
●
Scheduled tasks are displayed under the Schedule tab on the Rules admin pages
●
You can delete tasks manually if you want to
●
You can schedule tasks manually, without the need of reaction rules
●
It is sometimes useful to execute rule components manually, to see that the scheduled tasks will work
as expected
7. Best practice
● Make use of tags
● Use components to organize your rules
● Export your rules to feature modules using Features
● Keep your rules simple
8. Debugging
Rules provides a very useful debugging system. This allows us to follow all the steps of a
rule configuration as it's being executed.
12. Conditions
- hook_rules_condition_info()
- Implement function
[condition_name]():
– function arguments match
parameters + $settings;
– returns only boolean value;
– can’t provide variables;
– cannot save parameters;
13. Other Rules API hooks
● hook_rules_data_info()
● hook_rules_plugin_info()
● hook_rules_[action|event...]_info_alter()
● hook_default_rules_configuration()
● hook_rules_data_process_info()
● ...