One of the recurring requests in the Views Bulk Operations issue queue is to create a downloadable archive of files attached to nodes. While the general case is not trivial to solve, I was recently hired by research on BLOGS to write a more specific action: create a Zip archive of all images stored in imagefields. The ImageField Archive module is the result, and you can find a demo here.
{files} table, I needed to expose their data for using custom tokens. To this end, I implemented the hooks hook_token_list and hook_token_values. This allows filename patterns to include preset names as well as other file information.aggregate attribute for actions, which does just that: the action function signature becomes example_action($nids, $context) instead of example_action(&$node, $context).action_views_bulk_operations_form. Here's an example of using them:<?php
// @file mymodule.module
/**
* Implementation of hook_action_info().
*/
function mymodule_action_info() {
return array(
'example_action' => array(
'type' => 'node',
'description' => t('Example action label'),
),
);
}
/**
* Implementation of action_views_bulk_operations_form_options().
*
* These options will be saved along with other VBO settings in the view data and can be therefore exported.
*/
function example_action_views_bulk_operations_form_options() {
$options['zipname'] = '';
$options['filename'] = '';
return $options;
}
/**
* Implementation of action_views_bulk_operations_form().
*
* This form will appear on the "Bulk operations" style plugin settings page of the view admin,
* in a fieldset labeled after the action description.
*
* Form values will be passed to the action function in the $context['settings'] array.
*/
function example_action_views_bulk_operations_form($options) {
$form['zipname'] = array(
'#type' => 'textfield',
...
);
$form['filename'] = array(
'#type' => 'textfield',
...
);
return $form;
}
/**
* Implementation of action_views_bulk_operations_form_validate().
*/
function example_action_views_bulk_operations_form_validate($form, $form_state) {
// Perform your validation here.
}
/**
* Implementation of action_views_bulk_operations_form_submit().
*/
function example_action_views_bulk_operations_form_submit($form, $form_state) {
// Perform any additional action needed here.
}
/**
* Implementation of action().
*/
function example_action(&$object, $context) {
$zipname = $context['settings']['zipname'];
$filename = $context['settings']['filename'];
...
}
?>