Rules. Обзор, примеры, API.

1,612 views

Published on

  • Be the first to comment

  • Be the first to like this

Rules. Обзор, примеры, API.

  1. 1.
  2. 2. Rules Overview, use cases, API Artem Berdishev skype: berdishev [email_address]
  3. 3. What is Rules? <ul><li>This is module for developers, not for users </li></ul><ul><li>The main goal – replace a lot of custom code by some configurations in UI </li></ul><ul><li>Interaction between different modules </li></ul>
  4. 4. What is Rules? <ul><li>Widely uses Token and Entity Token modules </li></ul><ul><li>Consists from 3 main items: action, condition, reaction </li></ul><ul><li>Part of rules can be stored and used as components </li></ul><ul><li>Loops & Lists </li></ul><ul><li>Has nice debug option </li></ul>
  5. 5. Rule architecture <ul><li>Events – system event(s) to which one(s) rule will react </li></ul><ul><li>Conditions </li></ul><ul><li>Actions </li></ul>
  6. 6. Rule architecture <ul><li>Events </li></ul><ul><li>Conditions – in which cases it should react? </li></ul><ul><li>Actions </li></ul>
  7. 7. Rule architecture <ul><li>Events </li></ul><ul><li>Conditions </li></ul><ul><li>Actions – what should happen? </li></ul>
  8. 8. Components <ul><li>This is reusable part of rules </li></ul><ul><li>Use them in creation rules </li></ul><ul><li>Condition set (OR/AND), Action set, Rules set </li></ul><ul><li>Components’ evaluation can be scheduled (module Rules Scheduler) </li></ul>
  9. 9. Useful modules <ul><li>Rules links </li></ul><ul><li>Flag </li></ul><ul><li>Views Bulk Operations </li></ul><ul><li>Message </li></ul><ul><li>Rules Bonus Pack </li></ul><ul><li>Content access </li></ul><ul><li>Relation </li></ul><ul><li>… .. </li></ul>
  10. 10. Some small examples
  11. 11. <ul><li>Users can add content (status = waiting for approval). It’s not published </li></ul><ul><li>The notification will be sent to administrator </li></ul><ul><li>He could change status to Approved or Declined (+ notification to the author) </li></ul><ul><li>If Approved – author can publish/unpublish content </li></ul>
  12. 12.
  13. 13. RULES DEMO
  14. 14. <ul><li>Make use of tags </li></ul><ul><li>Use components to organize your rules </li></ul><ul><li>Export your rules to feature modules using Features </li></ul><ul><li>Keep your rules simple </li></ul><ul><li>Write descriptions for your rules </li></ul>
  15. 15. RULES API
  16. 16. Event API <ul><li>hook_rules_event_info() </li></ul><ul><ul><li>array keyed by event name; </li></ul></ul><ul><ul><li>options: title, group, variables etc; </li></ul></ul><ul><li>rules_invoke_event() </li></ul><ul><ul><li>call this function with event name as argument to trigger the event </li></ul></ul><ul><ul><li>for example, in any hook function </li></ul></ul>
  17. 17. Action API <ul><li>hook_rules_action_info() </li></ul><ul><ul><li>array – action name (prefixed with module name) as key; </li></ul></ul><ul><ul><li>options: label, group, parameter, provides, callbacks, etc. </li></ul></ul><ul><li>Implement function [action_name]() </li></ul><ul><ul><li>function arguments match parameters + $settings; </li></ul></ul><ul><ul><li>returns array of parameter or/and provides with their name as key; </li></ul></ul>
  18. 18. Condition API <ul><li>hook_rules_condition_info() </li></ul><ul><ul><li>array – condition name (prefixed by module name) as key; </li></ul></ul><ul><ul><li>options: label, parameters, group etc. ( same as action ) </li></ul></ul><ul><li>Implement function [condition_name]() </li></ul><ul><ul><li>function arguments match parameters + $settings; </li></ul></ul><ul><ul><li>should return boolean value; </li></ul></ul><ul><ul><li>can't provide variables; </li></ul></ul><ul><ul><li>cannot save parameters. </li></ul></ul>
  19. 19. Rules API <ul><li>hook_rules_data_info() </li></ul><ul><li>hook_rules_plugin_info() </li></ul><ul><li>hook_rules_evaluator_info() </li></ul><ul><li>hook_rules_data_processor_info() </li></ul><ul><li>hook_rules_[action|event|…]_info_alter() </li></ul><ul><li>hook_default_rules_configuration() </li></ul><ul><li>… .. </li></ul>
  20. 20. Resources <ul><li>The Rules module page on d.o. http://drupal.org/project/rules </li></ul><ul><li>The Rules way of life (London 2011) http://london2011.drupal.org/conference/sessions/rules-way-life </li></ul><ul><li>Screencast by Johan Falk (Itangalo) http://dev.nodeone.se/en/learn-the-rules-framework </li></ul>
  21. 21. Question? Artem Berdishev skype: berdishev [email_address]

×