Drupal 8 Rules Module: How to Set Up an Automated Workflow on Your Drupal Site

Let's say you're a Drupal website administrator. One admin vs an entire “army” of writers, who edit and publishing content on a regular basis. Wouldn't it be great if you could... somehow... trigger an action that'll notify you each time new content gets uploaded? That's when the Drupal 8 Rules module comes in.

To help you configure and automate all types of workflows:

  • from automated mailing
  • to publishing content at a specific time
  • to... notifying a customer that a product is back on stock.

To help you create “event-condition-action” workflows and put some otherwise repetitive and time-consuming processes on... autopilot.

And all this without having to write even one line of code...

Now, let's get deeper into details on:

  • how to use the Rules module in Drupal 8
  • why you'd work out Rules workflows instead of... writing your own custom module as an automated workflow solution
  • the benefit of reusable rules components 
  • the most powerful workflows that you can build with Rules

1. How to Use the Rules Module in Drupal 8

But first, let's define its functionality:

A contributed module that enables you to create automated workflows based on ECA rules (or "reaction rules"). Or “event-condition-action” rules.



Source: Droptica.com

In short, the whole process triggering the action you want to automate sums up to:

  • WHEN an event happens (i.e. user accesses a certain piece of content on your site)
  • IF a specific condition is met (i.e. that user has the “Anonymous” role)
  • ACTION gets triggered (i.e. a specific message pops up)

Tip: the “condition” is optional in this equation.

The good news is that you get all these events, conditions and actions, by default, once you install the module. Just select the ones that fit your needs and... put them together in a custom workflow.

Source: Drupal.org

But the great news is that:

You can always write and add your own fully customed ones.

The Drupal 8 Rules module integrates smoothly with other modules —  Content Access, Organic Groups, Drupal Commerce, Flag — that provide you with their own specific events, conditions, and actions to incorporate into your workflow.

2. Why Go with Rules Instead of Writing Your Custom Module?

Or better said: “When would you choose this workflow automation solution over writing your own module?”

When/if you're a Drupal site administrator and you won't have that much experience with the Drupal API or writing PHP code.

Then, Rules becomes such a convenient option:

  • it allows you to prototype and to inject powerful (customed) functionality into your website, with no need to touch one line of code
  • it allows you to configure your own workflows and automate specific actions or repetitive tasks on your Drupal site

It's all about empowering the user. That ever-green, ever-powerful Drupal philosophy.

3. The Drupal 8 Rules Components Are... Reusable

But first, let's try a concise definition of the Rules components:

They're the elements that make a rule, that you can “recycle” when setting up other rules, as well.

Here's an example for you:

Say you have this action: “Send a specific notification to the site admin”. You can add it to multiple different rules, such “A user comment has been added” or “A content writter has edited an article”.

Tip: if you enable the Rules Scheduler module, you can have your rules components run at a specific time in the future. For instance, you can schedule the action of closing comments for a specific post, say, 2 months after its publication.

4. Cool Things You Can Do with Rules: From Basic to Complex Ones

“What type of workflows can I create using the Drupal 8 Rules module? What actions can I automate, more precisely?” you might ask yourself.

Here are some of the most frequent ones:

  • timed twittering or emailing
  • automated audits
  • notify a customer when the reserved item is back in stock
  • notify a user when someone bookmarks his/her content
  • email a customer the copy of his order when his order status changes
  • notify the site administrator when one of the writers adds a new article
  • notify the admin about emergency log entries
  • publish a new article at a specified time
  • notify a user when someone adds a new comment to his post

And the list of scenarios that you can create and automate is... endless. 

5. Final Word

Now, it's only honest of me to mention that this module for workflow automation in Drupal 8 is still in its alpha phase (alpha5, to be more specific). So, you can't yet use it on production sites.

Nevertheless, you'd better be prepared for the day when it gets ported from Drupal 7 to Drupal 8.

For, judging by the powerful functionality that it stores, you'd want to be ready to... unleash it as soon as the light turns green and you can use it on your site.

Have you already used Rules in... Drupal 7 maybe?

Do you find its potential high enough to be looking forward to its official release in Drupal 8? Do you currently prefer writing your own custom modules for setting up automated workflows on your Drupal sites?

Let's start a conversation around these questions in the comments below:

Image by moritz320 from Pixabay