Actions in Views Bulk Operations

Views Bulk Operations come handy when doing bulk operations over a selected list. This is great because it combines the power of views to filter the selection and specific actions to do on each selected entity. For Ex: Updating some field in the record, deleting selected entity and so on.

Views also provide an easier way to define your own set of custom functions to perform on each selected row of entities.

First, we need to define an action :

Organic Groups Views Exposed Filter Selection

It becomes very frustrating when one had to try various options but not be able to create drop down list of groups for selection via an exposed filter option in a view.

There is a very simple solution to it. In the Group Audience field settings, select "Render Views filters as select list" option under ADDITIONAL BEHAVIORS. This selection would make the Group Audience field selected as an exposed filter display drop down options of all the groups available.

Change the text of Apply Button on views Exposed form

The following snippet changes the views exposed form Apply Button to Search Jobs. Make the changes in template.php file of the currently enabled default theme. Clear cache to see it work.(Clear class registry cache to be precise.)


function YOUR_THEME_NAME_preprocess_views_exposed_form(&$vars, $hook){
// only alter the required form based on id
// drupal_set_message(t("form id: ".$vars['form']['#id']), 'status', FALSE);
if ($vars['form']['#id'] == 'views-exposed-form-search-openings-page') {
// Change the text on the submit button

How to Modify Output of a View

Using views_pre_render hook one can alter the output of a view

* Implements hook_views_pre_render().
function jicustom_views_pre_render(&$view) {
$results = $view->result;
foreach ($results as $key => $result) {
$collection_name = $result->field_collection_item_field_name;
if($collection_name == 'field_transaction_items_outgoing'){
//Modify output
$results[$key]->field_field_trans_item_quantity[0]['rendered']['#markup'] = -($result->field_field_trans_item_quantity[0]['raw']['value']);

Provide a link to add content from VIEWS

I found out a better way to provide "Add content" link at the footer region of a VIEW. We can achieve followings:

- Pass any number of arguments.
- User can access link only if he/she has permission.

N.B- use Entity Reference for prepopulating valued from URL


global $user;
$view = views_get_current_view();
$args = $view->args[0];
if (user_access('create test_report content', $user)) {
$output=l(t('Add new Biochemistry Test '), 'node/add/test-report', array(
'query' => array(
'field_tr_patient_ref' =>$args,

Executing Views Bulk Operations Using Drush

Many times we use Views Buk Operations with Batch Api for doing a big set of operations. When the count of operations is huge, even Batch API gets short. A faster and more efficient way to do that is using drush to do the heavy backlifting.

The commands are:

vbo-execute      Execute a bulk operation based on a Views Bulk Operations (VBO) view.                                                   
vbo-list             List all Views Bulk Operations (VBO) views, along with the operations associated with each.


How to Set Filters for a View in Drupal 7 programmatically


Accessing a view programmatically

$view = views_get_view('view_name');
$view->set_display('default'); // or display id like page_1, block_1
//display_name = 'default' or 'page' and so on
//filter_name is the name of the filter

Extract Result Data From Drupal View


The code to do the trick is provided below:

= views_get_view('view_name');
$view->set_display('default'); // or display id like page_1, block_1
    //$view->set_arguments(array(arg(0),'arg_data2'));  // 2nd  Argument
drupal_set_message("Field data value: ".$view->result[0]->node_data_field_as_it_appears_in_views_query_sql);

Update for Drupal 7: