function batch_example_finished in Examples for Developers 8
Same name and namespace in other branches
- 6 batch_example/batch_example.module \batch_example_finished()
- 7 batch_example/batch_example.module \batch_example_finished()
- 3.x modules/batch_example/batch_example.module \batch_example_finished()
Batch 'finished' callback used by both batch 1 and batch 2.
Related topics
2 string references to 'batch_example_finished'
- BatchExampleForm::generateBatch1 in batch_example/
src/ Form/ BatchExampleForm.php - Generate Batch 1.
- BatchExampleForm::generateBatch2 in batch_example/
src/ Form/ BatchExampleForm.php - Generate Batch 2.
File
- batch_example/
batch_example.module, line 109 - Outlines how a module can use the Batch API.
Code
function batch_example_finished($success, $results, $operations) {
$messenger = \Drupal::messenger();
if ($success) {
// Here we could do something meaningful with the results.
// We just display the number of nodes we processed...
$messenger
->addMessage(t('@count results processed.', [
'@count' => count($results),
]));
$messenger
->addMessage(t('The final result was "%final"', [
'%final' => end($results),
]));
}
else {
// An error occurred.
// $operations contains the operations that remained unprocessed.
$error_operation = reset($operations);
$messenger
->addMessage(t('An error occurred while processing @operation with arguments : @args', [
'@operation' => $error_operation[0],
'@args' => print_r($error_operation[0], TRUE),
]));
}
}