Breaking

Followers

Tuesday, 16 January 2018

How to create Batch in Drupal 6, 7 with Example


URL = http://tylerfrankenstein.com/code/drupal-batch-example

/**
* The batch processor.
*/
function my_module_batch_fix_process($word, &$context) {
// Do heavy lifting here…
// Display a progress message…
$context[‘message’] = “Now processing $word…”;
}

/**
* The batch finish handler.
*/
function my_module_batch_fix_finished($success, $results, $operations) {
if ($success) {
drupal_set_message(‘Fix is complete!’);
}
else {
$error_operation = reset($operations);
$message = t(‘An error occurred while processing %error_operation with arguments: @arguments’, array(
‘%error_operation’ => $error_operation[0],
‘@arguments’ => print_r($error_operation[1], TRUE)
));
drupal_set_message($message, ‘error’);
}
drupal_set_message(l(‘Run again’, ‘my_module/batch_fix’));
}

No comments:

Post a Comment