This recipe describes the usage of condition groups and the ability to combine Conditions.
We'll create a rule that sends an e-mail to the administrators if either a new article or any content type gets posted on the site that has an image field (field_image
).
Create a new rule configuration and set the Event to Node | After saving new content.
Add a new Condition, Entities | Entity is new.
Add an OR Group.
Add a new Condition to the group by clicking on Add condition in the group's row, as shown in the following screenshot:
Add the Condition, Node | Content is of type and set the content type to Article.
Add another Condition to the OR group, use Entities | Entity has field and set the field to
field_image
.Add an Action to the rule configuration, use System | Send email to all users of a role, select the administrators role and fill out the SUBJECT and MESSAGE fields.
To create complex Conditions, in Rules we can use condition groups. This way we can create a chain of Conditions using AND or OR groups. AND groups require all Conditions within the group to evaluate to TRUE
, while OR groups require only one Condition to evaluate to TRUE
.
The following section describes combining of conditional groups:
We can also combine condition groups, that means we can create condition groups within condition groups. Again, it is advised that Debugging is turned on when creating nested condition groups as it can save a lot of time figuring out why a configuration doesn't work as expected.