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)

Preface

This book will demonstrate the power of the Rules framework that enables you to turn your Drupal 7 installation into an event- and action-based, interactive application. 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 level.

What this book covers

Understanding the basics of Reaction Rules (Must Know), demonstrates the basic use of Reaction Rules by creating a simple rule configuration and explaining how Events, Conditions, and Actions work.

Displaying a message on the site (Must Know), describes the steps to be taken in order to display a custom message on the site after creating a new article.

Sending e-mail notifications (Must Know), explains how to send a customized e-mail notification to all administrators when a new user registers on the website.

Sending notifications if someone comments on a node created by another user (Must Know), explains how to send a new comment notification e-mail to a node author using replacement patterns.

Using loops and lists (Must Know), demonstrates the basics of loops and lists by creating a list of objects in Rules and executing an Action on each item.

Components – Reusing Rules, Conditions, and Actions (Must Know), explains the benefits of using Rules components by creating a Condition that can be re-used in other rule configurations.

Using the Rules Scheduler (Must Know), demonstrates the Rules Scheduler by creating a rule configuration that sends a reminder e-mail to all users who haven't signed in for a week.

Debugging Rules (Must Know), explains how to use the built-in Rules Debug feature and provides hints and best practices.

Using PHP in Conditions and Actions (Should Know), demonstrates how to use PHP input in Conditions and Actions and provides hints regarding security and usage.

Using condition groups (Should Know), describes the usage of Condition groups and the ability to combine Conditions by creating a rule configuration 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

Subscribe to comments on a node using Rules and Flag (Should Know), explains how to use Rules and Flag to send out e-mail notifications to users when someone comments on a node users are subscribed to.

Adding a Taxonomy term to a node using Views Bulk Operations and Rules (Should Know), demonstrates how to execute Rules components on a Views Bulk Operations (VBO) view and explains how to expose components for VBO to work with.

Loading a list of objects into Rules using VBO (Should Know), describes how to add a specific taxonomy term to a list of nodes using Views Bulk Operations (VBO) and Rules.

Rules Bonus Pack (Should Know), demonstrates the Rules Bonus Pack module, which is a set of extensions and integrations with other modules to extend Rules to provide additional Events, Conditions and Actions, and also integrate with other modules, such as CTools.

Providing new Events, Conditions and Actions (Become an Expert), explains how to create custom Events, Conditions, and Actions for Rules by providing an example scenario where the number of times a view gets rendered is tracked by Rules.

Providing new entity tokens (Become an Expert), explains the basics of entity tokens and demonstrates how to create a new one that can be used in rule configurations.

Executing Rules programmatically (Become an Expert), explains how to execute Actions, Rules or rule sets programmatically by creating a new rule configuration and executing it from code.

Providing new variables for Actions (Become an Expert), explains how to modify existing or provide new variables and data for Rules in Actions by extending a previously defined Action that provides additional data to Rules after the Action is executed

Providing default rule configurations (Become an Expert), explains how to provide default rule configurations in code so that configurations can be maintained in code and version control, such as SVN or Git.

What you need for this book

A fully functional Drupal 7 installation is needed in order to complete the exercises in this book. Also, the following modules need to be installed and enabled:

  • Rules

  • Rules UI

  • Rules Scheduler

  • Views

  • Flag

  • Views Bulk Operations

  • Rules Bonus Pack

While the exercises in this book are written in a manner that aims to clearly and deeply explain each step, they presume that the reader has got basic understanding of the Drupal user interface.

Who this book is for

This book is for Drupal site builders and developers who want to take full advantage of the Rules framework's power and flexibility.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "It is also possible to modify a default rule configuration in code. For that we could use hook_default_rules_configuration_alter() in our *.rules_defaults.inc file."

A block of code is set as follows:

/**
* Implements hook_rules_event_info()
* Define our new custom event for Rules
*/
function custom_rules_event_info() {
  return array(
    'custom_views_render' =>	array (
      'label' => 'A view is rendered',
      'group' => 'Rules Custom',
      'variables' => array(
        'view' => array(
          'type' => 'custom_view_datatype',
          'label' => t('View being rendered')
        )
      )
    )
  );
}

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: " In the MESSAGE field, we've used REPLACEMENT PATTERNS to insert chunks of data from the objects available in our current rule configuration.".

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail .

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it