Search code examples
drupalbatch-filedrupal-7

Drupal 7 Batch Page Example


I'm trying to setup a batch page for processing and I need an example. The example that's given in the Example module is within a form and I need a page that I can run independently of a form that will process batch requests.

For instance:

function mymodule_batch_2() {
 $operations[] = array('mymodule_onefunction','mymodule_anotherfunction') 
 $batch = array(
  'operations' => $operations, 
  'finished' => 'mymodule_finished',
  // We can define custom messages instead of the default ones. 
  'title' => t('Processing batch 2'), 
  'init_message' => t('Batch 2 is starting.'), 
  'progress_message' => t('Processed @current out of @total.'), 
  'error_message' => t('Batch 2 has encountered an error.'),
);
  batch_set($batch);
  batch_process('');
}

Where the batch function would call other functions in the form of $operations.


Solution

  • You need to give batch process an id to work from. batch_process('mybatch')otherwise yourmexample is correct. are you having a particular problem with this strategy?