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 :

<?php
/**
 * Implements hook_action_info
 * Action to Send SMS
 * @return array
 */
function ji_custom_action_info() {
  return array(
   
'ji_custom_send_sms_action' => array(
     
'type' => 'node',
     
'label' => t('Send SMS to Donors'),
  
//   'behavior' => array('changes_property'),
     
'configurable' => FALSE,
     
'vbo_configurable' => TRUE,
     
'triggers' => array('any'),
    ),
  );
}
?>

Per Entity Configuration Form : For example, Text Message area for sending SMS or a predefined selected message template.

<?php
function ji_custom_send_sms_action_form($settings, &$form_state) {
 
$form = array();
 
$form['message'] = array(
   
'#type' => 'textarea',
   
'#title' => t('SMS Text Message'),
   
'#description' =>'Help Text',
   
'#required' => TRUE,
  );
  return
$form;
}

function
ji_custom_send_sms_action_submit($form, $form_state) {
 
$return = array();
 
$return['message'] = $form_state['values']['message'];
  return
$return; //Note, return value here must be an array.
}
?>

Defining the action to be performed for each selected entity

<?php
/**
 * Send SMS Action.
 * @param $node
 * @param $context
 */
function ji_custom_send_sms_action(&$node, $context) {
 
$message = t('Node title is %title. Sincerely, %hero', array(
   
'%title' => $node->title,
   
'%hero' => $context['message'],
  ));
 
drupal_set_message($message);
}
?>

--
https://www.drupal.org/node/2052067
https://api.drupal.org/api/examples/action_example!action_example.module...
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/func...