function BatchTestCallbacks::finishedHelper
Provides a common 'finished' callback for batches 1 to 7.
9 calls to BatchTestCallbacks::finishedHelper()
- BatchTestCallbacks::finished0 in core/
modules/ system/ tests/ modules/ batch_test/ src/ BatchTestCallbacks.php - Implements callback_batch_finished().
- BatchTestCallbacks::finished1 in core/
modules/ system/ tests/ modules/ batch_test/ src/ BatchTestCallbacks.php - Implements callback_batch_finished().
- BatchTestCallbacks::finished1Finished in core/
modules/ system/ tests/ modules/ batch_test/ src/ BatchTestCallbacks.php - Implements callback_batch_finished().
- BatchTestCallbacks::finished2 in core/
modules/ system/ tests/ modules/ batch_test/ src/ BatchTestCallbacks.php - Implements callback_batch_finished().
- BatchTestCallbacks::finished3 in core/
modules/ system/ tests/ modules/ batch_test/ src/ BatchTestCallbacks.php - Implements callback_batch_finished().
File
-
core/
modules/ system/ tests/ modules/ batch_test/ src/ BatchTestCallbacks.php, line 182
Class
- BatchTestCallbacks
- Batch callbacks for testing batches.
Namespace
Drupal\batch_testCode
public function finishedHelper($batch_id, $success, $results, $operations, $elapsed) : void {
$messages = [];
if ($results) {
foreach ($results as $op => $op_results) {
$messages[] = 'op ' . Html::escape((string) $op) . ': processed ' . count($op_results) . ' elements';
}
}
else {
$messages[] = 'none';
}
if (!$success) {
// A fatal error occurred during the processing.
$error_operation = reset($operations);
$messages[] = $this->t('An error occurred while processing @op with arguments:<br />@args', [
'@op' => $error_operation[0],
'@args' => print_r($error_operation[1], TRUE),
]);
}
// Use item list template to render the messages.
$error_message = [
'#type' => 'inline_template',
'#template' => 'results for batch {{ batch_id }} ({{ elapsed }}){{ errors }}',
'#context' => [
'batch_id' => $batch_id,
'elapsed' => $elapsed,
'errors' => [
'#theme' => 'item_list',
'#items' => $messages,
],
],
];
\Drupal::messenger()->addStatus(\Drupal::service('renderer')->renderInIsolation($error_message));
\Drupal::messenger()->addMessage('elapsed time: ' . $elapsed);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.