Leverage Views Bulk Operations to Manage Your Content

Not that Drupal's administrative screens are horrible but many times they lack the power needed to effectively manage a site's content. Administrators quickly run into limitations so in swoops Views Bulk Operations to save the day. The module lets you use Views to build lists of content, users, etc and provides users the functionality to all or select specific rows and apply an operation such as publishing, promoting, or deleting to each. The real benefit here is that you can use Views to build various displays with sorts and filters to make it easy to find and identity content then perform the operation.

You can create your own customizable pages or use Views to override the core pages. A fine example of using VBO to enrich your site's administrative screens is the Adminstration Views project. This is a part of my standard build as it provides alternatives to the standard content and user administrative pages. I usually clone these to create my own custom Views which I can adjust as needed, then get those into Features.

Action Integration

Views Bulk Operations utilizes Drupal's Action system to perform the operations. Plenty of standard operations are available out of the box, and other modules also provide additional actions which you may make available in the View.

If you'd like to provide a specific action to your site's editors, managers, administrators, or even yourself take a look at the Views Bulk Operations (VBO) development guide. It fairly trivial to write a module that implements a few action hooks with the necessary VBO parameters. The actions you define will then be available for configuration within the View.

But wait, it gets even better.

Executing arbitrary PHP code

One of the handiest actions in place provides the ability to "execute arbitrary PHP code" on each entity selected in the View. Here you can select the results you wish then provide a PHP snippet to do whatever you desire. This provides the flexibility to work with your content however you desire without having to deploy code.

Danger! It's highly-advised to do this in a test environment, or at least have a backup you can roll back to in case of disaster, i.e. user error.

Delete and Reset URL Aliases

I normally utilize Pathauto to manage aliases for nodes, etc and configure it to set the alias once and never change. This is to ensure links from external sites, bookmarks, or other ways people may link to the pages do not break. But sometimes it is necessary to update the alias--before launch or a widespread URL restructure, for instance. Here's where I can use VBO to allow me to filter only the content that I'm interested in, then initiate a batch operation to delete the old alias and reset a new alias generated by Pathauto.

pathauto_node_update_alias($entity, 'insert');

Set Field Data

Another useful thing to do is to set some data on the node. A particularly useful example is when you add a field to an existing content type and it needs to be populated with a value. You can use a VBO to set data on the node/entity and save it. If you're fancy you can even do some logic within the PHP snippet to set the desired value.

*Be advised that this is a down and dirty example of forcing some data into the field array of a node. The generally accepted way to accomplish this is using Entity metadata wrappers.

->field_is_odd[LANGUAGE_NONE][0]['value'] = $entity->nid % 2;

More Information

If you'd like more information, take a look at Views Bulk Operations project page. There you'll find documentation, other write-ups, screencasts, and a list of complimentary modules that provide even more VBO goodness.