ImageField Archive: an action to download zipped images

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.

Features

  • Provide a new action called "Download archive of images", that works with node views.
  • Show a settings form on the VBO admin page that allows to enter the patterns for naming the Zip archive and each image file in it. The patterns use the venerable Token module.
  • Show a user form during VBO execution that allows to select the ImageCache preset(s) to include in the archive.
  • Create the Zip archive and download it!

Technicalities

  • The PHP core class ZipArchive is needed to create the archive.
  • Because ImageCache presets don't have entries in the {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.
  • Normal actions are designed to be called with only one object at a time. In our case, however, we need all selected objects (the nodes in the VBO) to be passed at once to the action function, to simplify iterating over the nodes and placing the image files in the archive. A while ago, I had introduced the new aggregate attribute for actions, which does just that: the action function signature becomes example_action($nids, $context) instead of example_action(&$node, $context).
  • To show the action settings form on the VBO admin page (as opposed to during VBO execution), I introduced a series of new hooks for actions called 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'];
  ...
}

?>

Comments

Kerala is known for its normal excellence and social differing qualities. A wide and very much joined system of streets guarantees that this assorted qualities doesn't frustrate the solace of neighborhood individuals and sightseers. Being a mainstream vacationer destination, there are offices of extravagance mentors and traveler taxis for guests. Aside from roadways, ship watercraft and railroads are the other imperative methods of transport in Kerala. Ships are the most ideal approach to appreciate delight rides while seeing the stunning perspectives of backwaters of Kerala.

Taxis are the most ideal method for covering short separations in Kerala. Taxies for the most part incorporate autos such as Ambassadors and Tata Indica. Autos are additionally accessible on rent. The taxicabs can be useful in getting a charge out of the picturesque common magnificence of the state. These taxi administrations can be costly, however would offer incredible solace and extravagance to go on the streets of Kerala. In Kerala, call taxi kochi gives sheltered and solid 24 hour taxi contracting administrations for short separation and long separation ventures.

Intended to take into account your own, recreation or corporate travel, these administrations from buddycab.in Travel Division will satisfy every one of your yearnings of a protected and agreeable travel.It's administrations spread in the primary getting/dropping the visitor from the Railway Station/Airport, grabbing/dropping at the Hotel/Resort, taking you to/from corporate gatherings, courses or any vacationer destination of your decision in Kerala.