Book Image

Drupal Rules How-to

By : Robert Varkonyi
Book Image

Drupal Rules How-to

By: Robert Varkonyi

Overview of this book

Rules is what every Drupal site builder and developer has to use when creating event ñ action-based applications. The framework provides a highly flexible way to create sophisticated, condition-based functions any Drupal based system into an interactive application. Rules makes Drupal rule the CMS world."Drupal Rules How-to" is a practical, hands-on guide that provides you with a number of clear step-by-step exercises, which will help you take advantage of the real power of the Rules framework, and understand how to use it on a site builder and developer levelThis book demonstrates the power and flexibility of the Rules framework. It discusses the main aspects of the module both from the site builder and developer perspective, from basic and advanced Rule configurations using Events, Conditions, Actions and Components to getting familiar with the Rules API. You will also learn how to use additional modules together with Rules to further extend the possibilities of your Drupal system, such as Rules Scheduler to schedule the execution of your Rule configurations and Views Bulk Operations to execute Rule configurations on a view result list. The book also demonstrates the main API features that enable you to create your own Events, Conditions and Actions, provide new data types to Rules and execute your configurations programmatically
Table of Contents (7 chapters)

Using loops and lists (Must know)

This recipe explains the basics of lists and loops, creating a list of objects, and executing an action on each item.

How to do it...

  1. Create a new rule configuration and set the Event to Node | After saving new content.

  2. Add a Condition, Node | Content is of type and set it to Article.

  3. Add a new loop and set Data selector to node:field-tags.

  4. Add a new Action System | Show a message on the site and set a message.

How it works...

Using lists and loops in Rules is the way to handle multiple value fields and execute Actions on each individual item. While this particular recipe is not too useful in the real world, it can be used as a basis for more advanced features, for example, when using a node reference field to provide reference to a list of related nodes. We can then load that list of referenced nodes and create a loop that will send a customized e-mail notification to the authors of the referenced nodes.

There's more...

We can also add items to a list by adding an Action, Data | Add an item to a list. An example use case could be to automatically add a taxonomy term to the newly created node or add a user to a user reference list.