SyncShow
B2B Marketing Blog

Drupal Rules: My New Drupal Best Friend

drupalbestfriend-OPT

Not too long ago I heard a Drupalista speak of how long it takes to learn Drupal. He said it took four to five years. I found this to be true so far. I am approaching two years of developing in Drupal. It seems to me that the learning curve is more steep than flat.

I think I hit a learning plateau for a little while, but over the past month I have a new friend in Drupal modules. What is this module? Rules. Now, I have used this module before to do some complex order of items, but I never really understood exactly what they were doing.

How to Use Drupal Rules to Send Blog Notifications to Subscribers

A couple of recent projects brought me to a greater understanding of the Rules module. The first project required sending blog subscribers a notification of new blog content. For this I used the Simplenews module to deal with the subscriptions and Rules, Mimemail and Simplenews Rules to create and send the emails.

  • To set it up, I started by creating events of “After saving new content” and “After updating existing content” and set both to act on the blog node type.
  • For conditions, I created “Content is published” for the node.
  • I added a boolean field to the blog content type named “Newsletter sent” and set its default value to FALSE, then created a “data comparison” condition on the newsletter sent field to equal FALSE.
  • For the actions, I started by creating a new newsletter entity.
  • I set the title and body fields using the blog node data and the newsletter category appropriately.
  • I then had to set up an action to forcibly save the newly created newsletter, so that it could be sent with the newly set fields.
  • I then set the newsletter sent field to TRUE.
  • Finally, I created an action to send the newsletter.

How to Use Drupal Rules to Send Webform Data into a Database

Another project was for my church. We are setting up Drupal as our membership management software. The goal was to have a visitor form capture new visitor information and send it to the appropriate people. This is done by a simple webform. We also needed to get that webform data into the membership database and that’s where Rules fit in so well. The modules I used were Rules and Webform Rules.

  • To start, I used the “After a webform has been submitted” event.
  • I set the condition to “Webform has name” and set the value to the visitor’s webform.
  • Actions I added include “Add a variable” to store webform data, an action of “Create a new entity” type of member to create the member, and then a couple actions of “Set a data value” to set the member field data.
  • And again, an action to forcibly “Save entity” on the member.

As I am still new to understanding Rules, there are a few things I am still digging into. One thing is how to determine if a node exists with a specific field value, and if not create a new entity. I think this may be done by chaining rule set and rule components. This is next part I am learning more about.

After two years of developing in Drupal I have learned a lot, but still see so much more to learn. Not to mention the new developments in Drupal 8 that are coming in the near future.

Do you have any tips for Rules? Please share in the comments below.

Another post about Drupal from Harold:
9 Drupal Modules That Should Be Part of Every Website Build

 

Selling digitally

 

Image: The Drupal Five by Gabor Hojtsy via Creative Commons Attribution-ShareAlike 2.0 Generic License



Harold Knieriem
Posted by
Harold Knieriem on Thu, Sep 04, 2014 @ 08:30


Topics: Website Design & Development