It's done: Rules 2 is out!

Finally, slightly more than two years after I started the initial development I'm happy to announce the release of Rules 2.0 for Drupal 7!

So what's new compared to Rules 1.x?

While the fundamental concepts of "Event-Condition-Action rules" and parametrized actions remain, Rules 2.x is a complete re-write - quite some things changed. Now, it's building upon the Entity API module to fully leverage the power of entities and fields in Drupal 7. Change a taxonomy term? - No problem. Moreover that, Rules 2 now allows you to just select any entity property or field via it's so called "data selection" widget:

Data selection

The Rules data selection widget shows all suiting data properties when configuring an action or condition argument. Let's consider, you configure an action to send a mail - by using the data selector comment:node:author:mail you can easily send mail to the comment's node's author. For that the data selection auto-complete helps you finding suiting data selector:

You might note, that data selectors like node:title look like token replacements. But as actions need more than just textual data, the data selector gives them back the raw data, e.g. full entity objects or whatever fits depending on the data type. Thus, data selectors are not implement via token replacements, but via the entity.module's Entity property info system. Still, the Entity Tokens module (comes with Entity API) makes sure there are token replacements available for all the data selectors too.

The very same way one can naturally access fields too - e.g. node:field-tags gets you all the tags of your article node. However as only articles have tags, for that to work Rules needs to know that the variable node is an article first. Thus, make sure you've used the "Content is of type" or the "Data comparison" condition to check it's an article. Analogously, if you have an "entity" data item you can use the Entity is of type condition to make sure it's a node and access node-specific properties afterwards!

Read more about data selection in the drupal.org handbooks.

Switching parameter input modes

Related, Rules 2 allows you to switch the input modes while configuring the argument for an action parameter. Consider, you have an action that works with a vocabulary. Usually people might select the vocabulary to work with from the list of available vocabularies, but in some circumstances one wants the action to use the vocabulary of a specific taxonomy term. This is, where switching parameter input modes comes into play as it allows you to switch from fixed input mode (= configuring a specific vocabulary) to the data selection input mode - so you could just configure term:vocabulary as an argument by using the data selection widget.

Rules 2 provides small buttons below each parameter's configuration form which allow you to switch the input mode:

Components

Components are standalone Rules configurations that can be re-used from your reaction rules or from code. In Rules 1.x there are already "rule sets" available as "components" - but with Rules 2.x there are multiple component types: Rule Sets, Actions Sets, Rules, "AND Conditions Sets" and "OR condition sets". Rule sets come with maximum flexibility, but if the extra layer of having multiple rules is unnecessary for your use case, you can go with the simpler action set or a single "rule" component now! Next, the conditions sets make it possible to define re-usable condition components.

Components work upon a set of pre-defined variables (e.g. a node), just as for Rules 1.x. However with Rules 2.x it's now possible to provide new variables back to the caller, too.

Read more about components in the drupal.org handbooks.

Loops and lists

Rules 2 is finally able to properly deal with loops and lists! That means you can now access all your fields with multiple items, e.g. the tags of an article node. So you can easily loop over the list of tags and apply an action to each tag. That's also very handy in combination with node-reference or user-reference fields. Send a notification mail to all the referenced users? No problem.

Furthermore, one can access individual list items directly using the data selector - just use node:field-tags:0:name to access the first tag. If you do so, you might want to check whether a tag has been specified by using the "Data value is empty" condition though.

Read more about loops in the drupal.org handbooks.

Improved debug log

Fortunately, there has been another Rules related Google Summer of Code project this year. Sebastian Gilits worked on improving the rules debug log as part of his project! Now, the debug log makes use of some Javascript and appears all collapsed by default, so it's much easier to get which events have been triggered and which rules have fired in the first place. Also, we've included edit links so you can easily jump from the debug log to the Rules UI in order to fix up a miss-configured rule.

Upgrading from Rules 1.x?

There is an upgrade path in place which should work fine for basic installations - just make use of update.php as usual. Update.php is not going to convert your Rules 1.x rules to Rules 2.x though, that's done in a separate step. Check the REAMDE.txt for details.

What's next?

Now, as Rules 2 is out we'll continue to work on improving it to ensure it works fine in production. In particular, we'd like to concentrate on improving the UX and avoiding common pitfalls. Of course, any contributions and suggestions are highly welcome, as well as help working through the issue queue. See you there!

Lastly - at this point many thanks to epiqo for supporting Rules development and making all that possible :)

Comments

Kudos gentlemen, I'm certain this module will continue to grow in awesomeness for a long time to come :)

Sounds amazing! Great work... can't wait to get some time to play with it :)

Amazing work. Now I really need to learn to master rules, no more excuses to postpone it. Johan Falk's Learn the Rules framework is a great start.

Do you know fago?

I know the_real_fago!

Just dropped by to say thank you for the amazing work! Rules made so many modules obsolete

I hope you did the debug screenshot on a slow box, because when we addition everything, it cames up to 20ms which is huge.

Aside of that, interesting article, thanks.

Those times are already summed up.

Sorry to bother you. First of all many thanks for your amazing work.
I have though a problem when using Rules in Drupal 7. Something I used to be able to do in D6. I have a node field that is of type long text and is filered Full HTML. I set up a rule that after a certain event should populate that field with a certain html snippet. I put the condition the entity to contain that field. I think I did everything by the book but I cannot make that filed to contain html. I don't know what I'm doing wrong. Thank you for your eventual answer.

Cool! I want to try it sometimes! Thanks~
Forex Brokers

<?php echo "bien carnal es algo como lo que andaba buscando gracias";?>

petjecson's picture

Thanks for sharing this.

petjecson's picture

Thanks for sharing this.

C'eѕt іnfiniment dս bonheur de visiter votyre site internet

my web blog www.youbaise.tv

Add new comment

Filtered HTML

  • To post pieces of code, surround them with <code>...</code> tags. For PHP code, you can use <?php ... ?>, which will also colour it based on syntax.
  • Allowed HTML tags: <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.