Module Mondays: Views Bulk Operations

Robin Barre

on

January 21, 2008

Module Mondays: Views Bulk Operations

A couple of engineers at CivicActions were interested in the Views Bulk Operations module. Me too! So I checked it out. Easily installed, the most important bit I can tell you about is this:
  • clone the view that comes with views_bulk_operations (admin_content)
  • in the clone be sure to go to the Filters and select all content types for the Content Type filter (so you can see all nodes with the view)
  • click Save, then start messing with it!
The implications are immediate. As a developer, I can use views_bulk_operations for quick clean up of my many test nodes. For clients with savvy Drupal users, they can easily manipulate many nodes for improved site administration. Imagine reviewing a whole set of nodes, then publishing them all at once. The view could display the fields which need review, then just check the box next to each node and choose the Publish operation. The basic operations include promoting nodes to the front page (or demoting from the front page) plus sticky or delete (careful with that one) operations are available to apply to multiple nodes. When you add Actions module to the mix, there are even more operations available to you. My favorite: change node author I tried adding my own action through the Actions UI, but it did not show up in the list on Operations tab for my view. I am not an Actions expert, and I think it might work better if I had Workflow module installed and created an action to a specific workflow. It seems the Views Bulk Operations might need some work here or some documentation about how to add Actions that Views Bulk Operations can use. Other modules can add operations as well. For example, my creatively named module test1, sets up an operation in test1.module:
function test1_node_operations() {
  $operations = array('test1' => array(
    'label' => t('test1 node operations'),
    'callback' => 'test1_bulk',
    ));
  return $operations;
}

function test1_bulk() {
        drupal_set_message('test1_bulk ran');
  return;
}
test1_node_operations() was easily created after I reviewed Drupal's API: http://api.drupal.org/api/function/hook_node_operations/5 Working similarly to hook_menu(), it informs Drupal of the operation test1_bulk. views_bulk_operations finds test1_bulk and it is immediately available to any bulk view. An administrator will need to check the box for 'test1 node operations' in the Operations tab of the bulk view to make this new operation available to users. In this case, test1_bulk doesn't actually affect any node, but it gives you starting point. Overall, Views Bulk Operations has a ton of potential. With a little more clarity/development with Actions created through the Actions user interface, this module will be of great value to developers and administrators.

Share it!

There are some quirks to using actions. The one you are seeing is the fact that the Action module's email actions are *not* "batchable" for some odd reason. Actions must be batchable before they will show up on the views bulk operations configuration page. I needed a customizable email action for VBO, so I simply copied the action from actions.inc, made it batchable and had it use the Token API for text replacement rather than simple string replacement. That action now gets a lot of use and works fine. The key to getting the most out of VBO is creating custom actions. The default actions available are not very exciting. But when you start writing your own actions, VBO becomes very, very valuable. And you don't actually need the actions module. VBO also supports hook_node_operations(), which aren't as flexible as actions, but work well for simple, non-configurable node operations. Thanks for the review.
Thanks Robin for this concise overview! And for posting the first in our new series "Module Mondays".