Drupal 7 Views Bulk Operations and Rules module integration

By shane
Tue, 2012-11-20 19:46
Daily Dose of Drupal Episode #53

Share with Others

In this episode we go into more depth on the Drupal 7 Views Bulk Operations module and look at how it can be integrated in with the Drupal 7 Rules module for increased flexibility when building Drupal views using Views Bulk Operations.

In this episode you will learn:

  • How the Rules module and the Views Bulk Operations module can be used together to build more flexible administrative interfaces
  • How to trigger a Drupal 7 Rules action set using a Views Bulk Operations powered view

Hello everyone and welcome to another Daily Dose of Drupal. I’m Shane, as always you can follow me on Twitter @smthomas3, you can also go to codekarate.com website and sign up for the newsletter over hare.

Today we’re going to continue on learning about Views Bulk Operations and you can see if you haven’t already watched Episode Number 52, I would recommend watching that first, that’s going to go over the basics and also if you have not watched any of the episodes on the Rules Module which looks like episodes number 24, 25 and 26. They may be helpful, you’ve probably get through this without it but afterwards you may want to go back and watch those as well.
However; today we’re going to look at Views Bulk Operations and how to actually use Views Bulk Operations to execute or trigger a Rule and this obviously is very useful for building out very complex workflows and administration pages as we went over yesterday’s Views Bulk Operations allows you to create a View of … in our example we use Nodes but it can by any type of Entity; Users or any other entity that’s declared and create actions or excuse me, execute actions on multiple of those nodes users, etc and performs something.
So in yesterday’s example we were able to publish multiple post set one time or unsticky or sticky multiple nodes at one time using the Views Bulk Operations module. So let’s go ahead and pull up that View and we take a look at where we left off.

So we have a Views Bulk Operations test view that we created yesterday, as you can see it has the Bulk Operations field and then a couple of other fields, you can see an example down below, we’ll go ahead and we’ll go to the page so you can see what it looks like, you can see you have the Operations Field set up here, you can select multiple items from the View and execute actions on this.

What we’re going to do is we’re going to show you how to create a simple Rule, we’re not going to go too far on the Rules because we have that other episodes, I go on to that but how to execute a simple Rule from here. So instead of just selecting unpublished content we could say for Test Article 1 and Test Article 2 we want to run this Rule that may … let’s say you have guest post and you want to send an e-mail to all the authors using Rules, you could do something like that or you could … any type of workflow you could build with Rules or any type of actions you can tie in with the Views Bulk Operations module.

So the sky is really the limit and I guess you can pretty much figure out everything that your imagination might be able to come up with for multiple different scenarios of how this can be useful. So the first step; we’re going to download the Rules module using Drush, we go ahead and get that downloaded, I’m going to hop over to the modules page and you can see we have rules, I’m going to go ahead and install Rules and Rules UI, I will click Save, you need the Entity Tokens module as well so I’ll go ahead and let that be installed and now I’m going to go ahead and go to the Rules Configuration page and create a simple Rule, excuse me; we’re actually going to start … we’re going to go back here, we’re going to go ahead and look at the components, we’re going to add a new component.

So these components are stand alone sets of rules that can be used by Rules and other modules on your site so we’re going to add a new Component and we’re going to go ahead and say we want this to be an Action Set.

The Variable; we’re going to go ahead and say this is going to be a Node, we’ll go ahead and call this vbo_node, this is going to be a parameter, I’ll go ahead and hit Continue. Now that we have this Action Set created we’re going to go ahead and add a couple actions, we can for instance … we’ll say we’ll publish the Content and we’re going to … I’m going to go back and select Node here, we’re also going to go ahead we can send mail.

So we can go ahead and find … just keep this basic, we’ll just use the site e-mail address and we will say test e-mail, test message, we’re just going to going to go through and show some simple ways to get this setup and are working and obviously you can do whatever you want here, this one doesn’t really make sense, I guess you could say if someone is publishing content that wasn’t site owner and you wanted an e-mail to go out every time content was published from this interface you could use this rule, so we’re going to save it and it’s nothing in the settings that … we’ve already configured that, we’re going to save changes and now that’s saved we’re going to go back to our View and if everything is setup correctly you won’t notice any differences yet but we’ll come in and edit the View, we should be able to hopefully find that Actions Set in here.

You’ll notice when I go ahead and click on the Bulk Operations, that’s the checkbox field that we added and you’ll notice in here that there’s a Rules Action Set and you can choose to … and queue the operations which would be the queue it up and execute it later, you can skip the Confirmation step, you can override the label and we’ll go ahead and override and say publish an e-mail, so that’s what’s going to show up, we’ll go ahead and hit Apply All Displays, save it and we’ll give this a quick test.

So now if I go here you’ll notice there’s a Publish an E-mail, I’m going to go ahead and first make sure I unpublished this and I will hit Execute, it’s going to ask me to confirm it, now if I open this up you’ll notice it looks like my homepage is blank. I will now go ahead and run publish an E-mail, I will go ahead and execute that, there we go, and I go ahead and hit Confirm and now it’s going to run through this Rule and it might take a little bit of time because that’s what few more Operations, If I run to the homepage you can see both these articles are now published, I’m going to go ahead and open up my e-mail quick just to make sure that I got that and obviously this isn’t a very useful used case because I’m going to get multiple e-mails so it really … you’ve probably not use this exact use case because as you can see I had two e-mails that say test message, they all both had the test e-mail subject.

So you can obviously figure out your own use cases but what this will allow you to do is build out and it really expand on what Views Bulk Operations can do to pretty much build out any type of workflow you want without actually having to write any custom code.

So it’s super easy to get started and I recommend you try it out because this can make building an administration back end of your site, incredibly easy and incredibly flexible and I highly recommend trying it out. That’s it for this time on the Daily Dose of Drupal; we’ll be back again tomorrow with another exciting episode. Thank you for watching.


Post new comment