Drupal 8 Module of the Week: Rules

Each day, between migrations and new projects, more and more features are becoming available for Drupal 8, the Drupal community's latest major release. In this series, the Acquia Developer Center is profiling some prominent, useful, and interesting projects--modules, themes, distros, and more--available for Drupal 8. This week: Rules.

Preparing this post, I spoke with Wolfgang Ziegler--fago on Drupal.org--the creator of Rules, as well as Klaus Purer (klausi) and Josef Dabernig (dasjo), both major contributors and part of the effort to upgrade Rules to Drupal 8.

Wolfgang Ziegler is founder and CEO/CTO of the Vienna-based Drupal company drunomics and has been using and contributing to Drupal for more than ten years. He helps maintain core sub-systems like the Entity-, Form-, and Typed-Data Systems and is author of popular contrib modules like Rules, Entity API, Profile2, and Field Collection.

The port of Rules to Drupal 8 was supported by the Acquia Drupal 8 Module Acceleration Progam and a host of other sponsors. See below for as complete a list of thank yous as I could get--thank you all!

What does the Rules Module do?

The Rules Module provides site builders and administrators with a powerful user interface to create custom automated workflows on a website, without any coding, using "reactive" rules. Reactive rules are also known as ECA rules: an Event happens under a certain Condition, triggering an Action. Site builders can use the Rules module to react when something happens on a site and conditionally manipulate data or execute any logic necessary. Rules even lets you schedule tasks for the future on a one-off or recurring basis. A classic example would be when you create a rule for your site to email you when someone posts a comment, but Rules is in active use on roughly 300,000 Drupal websites and covers a huge number of other use cases.

Reactive (ECA) rules diagram

Josef Dabernig told me, "We have a couple of interviews as part of the Rules Initiative where one quote I like was, 'Rules eliminates the middleman. It empowers those who know about their business use cases to actually implement them using site-building tools--the user interface--on Drupal websites,' that is, without having to know how to write any code." Putting power into the hands of the end-user is what I call 'Drupal's most important design decision,' and Rules is an impressive expression of that ideal. And Josef also suspects that since Rules includes loops and conditions, it may well be a Turing complete programming language at the user interface level, too. :-O

However, at the code level. Rules is also tightly integrated with Drupal core APIs and all structured data exposed through the Entity and Field systems. Contributed modules can extend the module by providing additional events, conditions, and actions. In Drupal 7, hundreds of other contributed modules take advantages of Rules' flexibility and integrate with the Rules API.

Why is this important?

Developers can save a lot of time by off-loading commonly needed tasks to Rules. Instead of writing one-off, potentially less-compatible code, taking advantage of Rules and its API gives you standardized, compatible, repeatable ways to do things like checking any kind of user-configurable conditions before taking some (also configurable) action, like for example, checking whether a commerce discount needs to be applied to a particular purchase.

Josef pointed out in this context, "It's really the part of the ecosystem where everything connects. So it's not just the Rules module itself that makes the difference, but the power of the Rules module comes from the integrations it makes possible. In Drupal 7, we have over 300 modules like the Flag module, like Views, Bulk Operations, they all integrate and create this powerful, rich tool where Rules can then hook into all the data structures of the website. Rules can trigger any events that maybe the Workbench Moderation module provides or Rules can perform actions defined by other integration modules."

Site owners and administrators are empowered to configure various custom workflows without having to code. That way it helps to save time and makes a lot of changes possible without having to involve a developer. So when they say "Rules eliminates the middleman," it means Rules helps because we don't always want to have to go to a developer just to customize a string as part of an email notification, or we want to be able to change the tax rates on our eCommerce site ourselves, as needed.

A 2014 video with Drupal users and developers explaining what Rules does and why it is important to get it fully ported to Drupal 8.

When was Rules created?

Wolfgang Ziegler originally created the module in 2007 for Drupal 5, under the name Workflow-NG for Drupal 5. As the name says, it was created to allow for more flexible workflows. The Rules module first appeared for Drupal 6 and was entirely rewritten and enhanced for Drupal 7 as part of Wolfgang's computer science Master's Degree thesis.

Has Drupal 8 changed this module?

"The Drupal 8 port of Rules is another re-write, based on the APIs that Drupal 8 provides, that were missing in Drupal 7," Wolfgang explains, "Having the Drupal 8 the Context API, the Plugin and Configuration Systems helps simplify and reduce the module's custom code base. We can build upon standard solutions in core instead of having to come up with solutions on our own. This also greatly improves interoperability throughout Drupal. For example, configuration export and import uses the D8 core Configuration system, while in Drupal 7 the Entity API module's exportable system had to be invented and tacked on to fill that need."

More information

For more information on Rules, links, documentation, and how you can help, see:

  • http://d8rules.org/d8rules - the D8 Rule Initiative homepage
  • https://www.drupal.org/project/rules - the Drupal.org Rules project page

Thank you!

Talking about the support and sponsorship that helped keep the hard work and code contributions that have gone into porting Rules to Drupal 8 happening, Josef expressed his thanks: "Thanks to the sponsorship by Acquia and thanks to all the sponsors from the first funding runs where 300 people chipped in via crowdfunding on Drupalfund.us. The next biggest sponsor after Acquia was Technocrat and then we have Lingotek, Data in Transit, erdfisch, Zensations, Code Enigma, undpaul, Attiks. Thanks also to the supporting companies Drunomics, epiqo, and ausgetrock.net."