8.5.x form.api.php hook_batch_alter(&$batch)
8.0.x form.api.php hook_batch_alter(&$batch)
8.1.x form.api.php hook_batch_alter(&$batch)
8.2.x form.api.php hook_batch_alter(&$batch)
8.3.x form.api.php hook_batch_alter(&$batch)
8.4.x form.api.php hook_batch_alter(&$batch)
8.6.x form.api.php hook_batch_alter(&$batch)
7.x system.api.php hook_batch_alter(&$batch)

Alter batch information before a batch is processed.

Called by batch_process() to allow modules to alter a batch before it is processed.

Parameters

$batch: The associative array of batch information. See batch_set() for details on what this could contain.

See also

batch_set()

batch_process()

Related topics

1 function implements hook_batch_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

overlay_batch_alter in modules/overlay/overlay.module
Implements hook_batch_alter().
1 invocation of hook_batch_alter()
batch_process in includes/form.inc
Processes the batch.

File

modules/system/system.api.php, line 4646
Hooks provided by Drupal core and the System module.

Code

function hook_batch_alter(&$batch) {

  // If the current page request is inside the overlay, add ?render=overlay to
  // the success callback URL, so that it appears correctly within the overlay.
  if (overlay_get_mode() == 'child') {
    if (isset($batch['url_options']['query'])) {
      $batch['url_options']['query']['render'] = 'overlay';
    }
    else {
      $batch['url_options']['query'] = array(
        'render' => 'overlay',
      );
    }
  }
}

Comments

quicksketch’s picture

If you'd like to add your own custom CSS to progress bars and you keep it in a separate file, you can use this snippet in your theme's template.php to ensure your progress.css gets added on BatchAPI pages.

/**
 * Implements hook_batch_alter().
 */
function mytheme_batch_alter(&$batch) {
  // Add our own CSS to all Batch API operations to style the progress bar.
  $additional_css = array(drupal_get_path('theme', 'mytheme') . '/css/progress.css');
  foreach ($batch['sets'] as $key => $set) {
    if (isset($set['css'])) {
      $batch['sets'][$key]['css'] = array_merge($set['css'], $additional_css);
    }
    else {
      $batch['sets'][$key]['css'] = $additional_css;
    }
  }
}