function batch_example_finished

Same name in other branches
  1. 3.x modules/batch_example/batch_example.module \batch_example_finished()
  2. 7.x-1.x 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 modules/batch_example/src/Form/BatchExampleForm.php
Generate Batch 1.
BatchExampleForm::generateBatch2 in modules/batch_example/src/Form/BatchExampleForm.php
Generate Batch 2.

File

modules/batch_example/batch_example.module, line 109

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),
        ]));
    }
}