Taming the Butler: Learning Rules

Tuesday, October 25, 2011 - 13:37

With this blog post I’d like to summarize the content of the Learn the Rules framework screencasts, and give curious Drupalistas some easy entrances to one of Drupal’s most powerful and complex modules.

In early september I started publishing “Learn the Rules Framework” – a screencast series introducing the Rules module, and how to use it with some of its related modules. It is now nearly finished, and must be called a smash hit. The more than thirty screencasts have been viewed 5000+ times, and the first episode has more than a thousand plays by itself. Wow! I’m also overwhelmed by the positive reactions I’ve got from both people learning from the screencasts, and from maintainers of the modules covered in the screencasts. Thank you all!

What is Rules?

Rules is a framework for managing events, conditions and not least actions. It allows site builders to configure actions that should happen on certain events, and optionally only execute these actions if selected conditions are met. This can be both simple and quite complex things:

A very important part of Rules is its data and configuration management. It allows different parts of Rules (and other modules) to communicate about what type of parameters a plugin expects or provides. It also allows site builders to access this data in a quite slick way. The data management largely builds on Entity API, but extends it to allow non-entity variables to be managed in the same framework.

I am new to Rules – where should I start?

If you haven’t used Rules before, you should be aware that it is a module as complex as Views. Prepare for banging your head against the wall a few times – put on your helmet, and don’t expect everything to be crystal clear from the start.

I recommend the following path to start with Rules:

  1. View episodes 1–6 in the screencast series, introducing concepts like data types, lists and loops and creating non-trivial conditions.
  2. Watch episodes 7–11, showing some basic examples of Rules configuration – configuration that doesn’t require any additional modules or particularly complex configuration.
  3. Play around with Rules and create your own reaction rules for a while. Make sure you check out the conditions data comparison and entity has field, plus the action set a data value. These are important.
  4. If your configuration doesn’t work as you expect, watch episode 13 about debugging. It will save you time.
  5. Watch episode 6 – components – again, and then watch the introduction to using Views Bulk Operations in episodes 17–19.
  6. Play around with Rules components and VBO, and create yourself a nifty administration page or two. (This is a good and non-complex way of getting familiar with components.)

I’ve used Rules in Drupal 6 – what’s new in Drupal 7?

The changes between Rules 1 and Rules 2 (D6/D7) are big. The most important change is the data management, which takes some time to get used to. (I personally felt that Rules 2 was awkward and not really a success the first month or so, but I now feel that Rules has gotten some really important and really well-made improvements.)

If you want to get familiar with Rules for D7, I recommend the following:

I’ve seen Rules before – where can I watch the cool stuff?

Ah – the cool stuff! You should check out the following:

I’m a coder – what should I know about Rules?

  • Check out how configuration parameters are managed in Rules. If you expose your data to Entity API, Rules will know about it.
  • If you’re building modules with configurable conditions or actions, you should check out the components Rules provides. They are easy to implement in your module, and could save you a lot of time.
  • You could also consider exposing your own actions/conditions as Rules plugins. There is quite good online documentation, and I incidentally also made a screencast series about writing Rules plugins.
  • Similarly, if you’re building modules where you introduce new events that might be interesting for other modules to act on – tell Rules about them. It is a little bit more complex than writing actions and conditions, but not much. (Check out the documentation links above.)
  • If you ever get stuck, the rules.api.php file is an invaluable resource when coding for Rules. Also, you can stop by at #drupal-rules on IRC.


None of the links to the Rules videos work.