How-to: be notified of comments to approve with Drupal 5 and Workflow-ng

One of the great features of Wordpress is that you can set up your site to send an email every time a comment needs approval. Drupal doesn't come with this functionality out of the box, but we're going to show you how to do it yourself using the module Workflow-ng and some basic user configurations.

What you'll need

  1. A Drupal 5 installation (Drupal 6 can do something similar using the Rules module).
  2. The Workflow-ng module uploaded and activated. You only need to enable the "Workflow-ng" and "Workflow-ng UI" components.

The versions used in this tutorial are Drupal 5.15 and Workflow-ng 2.2 if that helps any.

Step-by-step instructions

1. Configure user roles

You'll want to have two separate roles: an anonymous user role who will be posting comments, and the role that will approve the comments. The anonymous user is already created in Drupal, but you'll want to create one more role that will receive the email to approve the comment. I called mine "super admin". Make sure whoever is moderating comments is in that user role.

Drupal user roles

Go to the Access Control screen (yoursite.com/admin/user/access), and make sure that the "post comments without approval" permission is unchecked. For your moderator role, make sure that the "administer comments" permission is checked. Save your changes.

2. Configure Workflow-ng

Workflow-ng is a powerful little module that lets you set up criteria and trigger actions when those criteria are met. Our rule is to send an email to the comment moderator when an anonymous user submits a comment. Lets translate this into Drupal-speak:

Create a new rule: go to the Workflow-ng admin page (you'll see a link at the bottom of the navigation menu. If you don't, give your account the "administer workflow-ng" permission). Click on the "Add a new rule configuration" tab at the top of the screen. For "Event" select "Comment has been created" from the dropdown. Give your rule a name, and make sure the "this rule is active" box is checked. Click Submit.

Workflow-ng comment moderation

Add a Condition: Since we only want to get notified when anonymous users post comments, we need to have the system check to this condition before sending. Click the "Add a condition" link on the next page. From the dropdown, select "user has role(s)", and click Add.

On the next screen, make sure the "User to test" dropdown is set to "created comment author", and select "anonymous user" as the role. Click Submit to save.

Add the action: Now we need to specify that we want to send an email once the user makes a comment. Click on the "Add an action" link, and from the dropdown select "Send mail to all users of a role" and click Add.

On the next screen, check the box next to the role who should receive the email. Give your email a subject line, and write a snappy message. I included information on the comment and where to approve it to make it easy for the moderator. Workflow-ng gives you a list of dynamic tags that you can use in your email to give the moderator additional info on the comment. Click Submit.

Drupal email comment notification

3. Test the crap out of everything!

The #1 rule of web development is test, test, test. Log out of your site and go to your blog (or any other post that is open for comments). Leave a comment (don't worry, you can delete it later). Check your email, and you should have some email love in your inbox. You got your email? Good.

Now you'll want to test as a logged-in user to make sure you're not getting emails for comments that are already approved. Log back into your site, and go back and post another comment. Did you get an email? No? Cool, then everything is working right!

And you're done! Congratulations on rocking your first Workflow-ng rule.

Read more: Drupal, CMS

1 Comment on this post:

I just found other topics on other sites explaining how it's possible to use the "Trigger" and "Action" functionality built in to D6

I just set this up on my site to be notified of incoming comments and it works a charm - nice and simple too

Basically:
1. Enable the Trigger module
2. Administer > Site Configuration > Actions > "Make a new advanced action available" (bottom of built in action list) > "Send email..." from drop down
3. Fill out the form taking note of the system variables - the email address is the recipient, ie the webmaster / moderator
4. Administer > Site Building > Triggers > Comments "tab" (top of page that I completely missed for 5 mins, lol) > "Trigger: After saving a new comment" and "Trigger: After saving an updated comment" choose your action from the drop down (mine ended up under the "System" category

5. TEST!

PS Thanks for this page and all the others, there's some really useful stuff here, well explained too :D

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><p><h1><h2><h3><h4><h5><blockquote>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
We hate spam, and this question makes sure you're not one of the bad guys.

Recent Blog Posts

Contact Us
Phone: Voice 630.303.9846
Fax: 630.689.9413
PO Box 2191
Glen Ellyn, IL 60138
Skype: two-trees-media
Powered By:

Powered By DrupalPowered by Media Temple

© 2010 Two Trees Media, LLC. All Rights Reserved. Valid XHTML & CSS. Site Map