This section describes the basics of Reaction Rules, Events, Conditions, and Actions.
We'll create a simple rule that makes newly created articles sticky.
Go to Configuration | Workflow | Rules.
Click on Add new rule.
Enter a name for this rule configuration, as shown in the following screenshot:
Enter values for Tags if required (they can be useful for categorizing rule configurations).
Set the Event to Node, after saving new content.
Go to the Condition, Node | Content is of type and set the value to Article by selecting it in the select box.
Add an Action, Data | Data selector and select the sticky field of the node.
Hit Continue.
Tick the Value checkbox.
Click on Save.
With the following steps, we're telling Rules to do the following: whenever a new content has been created and its content type is Article, set its sticky value to TRUE
. This rule configuration will be executed every time a new article has been created.
Let's have a look at the way Events, Conditions, and Actions work.
A reaction rule always needs a specified event to happen on the site so it will execute. This can be done when a user logs in, when a node is created, or various other Events are provided by Rules (or other contributed/custom modules). Events may provide variables that can be used in the configuration. For example, if the event is Node | After saving new content, the created content object will be available in the rest of the rule configurations for Rules to work with.
A reaction rule can have multiple triggering Events. For example, we can execute the same Action when we delete a node or when we delete a comment.
We can use Conditions to check some data, that's available in our current configuration, because we usually want to execute an Action only if certain criteria are matching. For example, we might want to check a node's type (Content is of type), whether a node has a particular field (Entity has field) or a truth value (Data comparison). There are a number of Conditions provided by default, but it's also possible to create our own Conditions in our custom module.
Conditions can be grouped into AND or OR groups. These groups can be used to create complex Conditions and each group may have additional AND and OR groups.