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

22
1

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

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

1

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

RulesOverview, use cases,

APIArtem Berdishev

skype: [email protected]

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

What is Rules?

• This is module for developers, not for users

• The main goal – replace a lot of custom code by some configurations in UI

• Interaction between different modules

3

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

What is Rules?

• Widely uses Token and Entity Token modules

• Consists from 3 main items: action, condition, reaction

• Part of rules can be stored and used as components

• Loops & Lists• Has nice debug option

4

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

Rule architecture

• Events – system event(s) to which one(s) rule will react

• Conditions

• Actions

5

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

Rule architecture

• Events

• Conditions – in which cases it should react?

• Actions

6

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

Rule architecture

• Events

• Conditions

• Actions – what should happen?

7

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

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)

8

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

Useful modules

• Rules links• Flag• Views Bulk Operations• Message• Rules Bonus Pack• Content access• Relation• …..

9

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

Some small examples

10

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

• 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

11

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

12

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

RULES DEMORULES DEMO

13

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

• Make use of tags• Use components to organize your

rules• Export your rules to feature modules

using Features• Keep your rules simple• Write descriptions for your rules

14

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

RULESRULES APIAPI

15

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

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

16

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

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;

17

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

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;– can't provide variables;– cannot save parameters.

18

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

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()• …..

19

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

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

20

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

Question?

Artem Berdishevskype: berdishev

[email protected]

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

22