RulesOverview, use cases, API                 Artem Berdishev                  skype: berdishev            berdart@amgrade...
What is Rules?• Module for developers• Custom code replaced by some  configuration• Interaction between different modules ...
Rules features•   Token and Entity Token•   Loops & Lists•   Nice debug mode•   Components•   Scheduler                   ...
Rule architecture• Events – system event(s) to which one(s) rule will react• Conditions• Actions                          ...
Rule architecture• Events• Conditions – in which cases it should react?• Actions                                          5
Rule architecture• Events• Conditions• Actions – what should happen?                                  6
Components• This is reusable part of rules• Use them in creation rules• Condition set (OR/AND), Action  set, Rules set• Co...
Useful modules•   Rules links•   Flag•   Views Bulk Operations•   Message•   Rules Bonus Pack•   Content access•   …..    ...
Some small examples• On node creation/saving change URL alias  pathauto• Notify admin (moderator, author) about  content p...
Big example - Workflow• Users can add content (status = waiting  for approval). It’s not published• The notification will ...
Scheduled publishing• Field for setting publishing (unpublishing)  date• Components for (un-)publishing and  logging• Rule...
RULES DEMO             12
Best practices• Make use of tags• Use components to organize your rules• Export your rules to feature modules using  Featu...
RULES API            14
Event API• hook_rules_event_info()  – array keyed by event name;  – options: title, group, variables etc;• rules_invoke_ev...
Action API• hook_rules_action_info()  – array – action name (prefixed with module name) as    key;  – options:    label, g...
Condition API• hook_rules_condition_info()  – array – condition name (prefixed by module name) as    key;  – options: labe...
Rules API•   hook_rules_data_info()•   hook_rules_plugin_info()•   hook_rules_evaluator_info()•   hook_rules_data_processo...
Resources• The Rules module page on d.o. http://drupal.org/project/rules• The Rules way of life (London 2011) http://londo...
Question?         Artem Berdishev          skype: berdishev    berdart@amgrade.com
Upcoming SlideShare
Loading in...5
×

Rules

268

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
268
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Rules

  1. 1. RulesOverview, use cases, API Artem Berdishev skype: berdishev berdart@amgrade.com
  2. 2. What is Rules?• Module for developers• Custom code replaced by some configuration• Interaction between different modules 2
  3. 3. Rules features• Token and Entity Token• Loops & Lists• Nice debug mode• Components• Scheduler 3
  4. 4. Rule architecture• Events – system event(s) to which one(s) rule will react• Conditions• Actions 4
  5. 5. Rule architecture• Events• Conditions – in which cases it should react?• Actions 5
  6. 6. Rule architecture• Events• Conditions• Actions – what should happen? 6
  7. 7. Components• This is reusable part of rules• Use them in creation rules• Condition set (OR/AND), Action set, Rules set• Components’ evaluation can be scheduled (module Rules Scheduler) 7
  8. 8. Useful modules• Rules links• Flag• Views Bulk Operations• Message• Rules Bonus Pack• Content access• ….. 8
  9. 9. Some small examples• On node creation/saving change URL alias pathauto• Notify admin (moderator, author) about content posting notification• Notify user (author) about new comments for node comment_notify• Custom breadcrumbs for node types custom_breadcrumb• … 9
  10. 10. Big example - Workflow• Users can add content (status = waiting for approval). It’s not published• The notification will be sent to administrator• He could change status to Approved or Declined (+ notification to the author)• If Approved – author can publish/unpublish content 10
  11. 11. Scheduled publishing• Field for setting publishing (unpublishing) date• Components for (un-)publishing and logging• Rule for – reaction on changing date field – scheduling the component evaluation Scheduler 11
  12. 12. RULES DEMO 12
  13. 13. Best practices• Make use of tags• Use components to organize your rules• Export your rules to feature modules using Features• Keep your rules simple 13
  14. 14. RULES API 14
  15. 15. Event API• hook_rules_event_info() – array keyed by event name; – options: title, group, variables etc;• rules_invoke_event() – call this function with event name as argument to trigger the event – for example, in any hook function 15
  16. 16. Action API• hook_rules_action_info() – array – action name (prefixed with module name) as key; – options: label, group, parameter, provides, callbacks, etc.• Implement function [action_name]() – function arguments match parameters + $settings; – returns array of parameter or/and provides with their name as key; 16
  17. 17. Condition API• hook_rules_condition_info() – array – condition name (prefixed by module name) as key; – options: label, parameters, group etc. (same as action)• Implement function [condition_name]() – function arguments match parameters + $settings; – should return boolean value; – cant provide variables; – cannot save parameters. 17
  18. 18. Rules API• hook_rules_data_info()• hook_rules_plugin_info()• hook_rules_evaluator_info()• hook_rules_data_processor_info()• hook_rules_[action|event|…]_info_alter()• hook_default_rules_configuration()• ….. 18
  19. 19. Resources• The Rules module page on d.o. http://drupal.org/project/rules• The Rules way of life (London 2011) http://london2011.drupal.org/conference/sessions/rules-way-life• Screencast by Johan Falk (Itangalo) http://dev.nodeone.se/en/learn-the-rules-framework• Demo sandbox on d.o. http://drupal.org/sandbox/BerdArt/1434760 19
  20. 20. Question? Artem Berdishev skype: berdishev berdart@amgrade.com
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×