Reader small image

You're reading from  Drupal Rules How-to

Product typeBook
Published inNov 2012
Reading LevelIntermediate
PublisherPackt
ISBN-139781849519984
Edition1st Edition
Languages
Tools
Concepts
Right arrow
Author (1)
Robert Varkonyi
Robert Varkonyi
author image
Robert Varkonyi

Robert Varkonyi is a senior Drupal developer and author, originally from Hungary. He has worked with clients across the globe, such as NBC Universal and Ericsson. Robert is currently working with Tincan, a leading Drupal agency within the arts, cultural, and NfP sectors. He is also the author of Drupal Rules How-to.
Read more about Robert Varkonyi

Right arrow

Understanding the basics of Reaction Rules (Must know)


This section describes the basics of Reaction Rules, Events, Conditions, and Actions.

We'll create a simple rule that makes newly created articles sticky.

Getting ready

Enable the Rules and Rules UI modules on your site.

How to do it...

  1. Go to Configuration | Workflow | Rules.

  2. Click on Add new rule.

  3. Enter a name for this rule configuration, as shown in the following screenshot:

  4. Enter values for Tags if required (they can be useful for categorizing rule configurations).

  5. Set the Event to Node, after saving new content.

  6. Go to the Condition, Node | Content is of type and set the value to Article by selecting it in the select box.

  7. Add an Action, Data | Data selector and select the sticky field of the node.

  8. Hit Continue.

  9. Tick the Value checkbox.

  10. Click on Save.

How it works...

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.

There's more

Let's have a look at the way Events, Conditions, and Actions work.

Events

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.

Conditions

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.

Actions

Rules Actions are tasks that Rules may perform. There are a number of Actions that Rules provides by default, such as setting a value, publishing a node, or creating a new entity. Other than the core Actions, we can also create Actions in a custom module.

Previous PageNext Page
You have been reading a chapter from
Drupal Rules How-to
Published in: Nov 2012Publisher: PacktISBN-13: 9781849519984
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Robert Varkonyi

Robert Varkonyi is a senior Drupal developer and author, originally from Hungary. He has worked with clients across the globe, such as NBC Universal and Ericsson. Robert is currently working with Tincan, a leading Drupal agency within the arts, cultural, and NfP sectors. He is also the author of Drupal Rules How-to.
Read more about Robert Varkonyi