You are here

function batch_example_op_1 in Examples for Developers 8

Same name and namespace in other branches
  1. 6 batch_example/batch_example.module \batch_example_op_1()
  2. 7 batch_example/batch_example.module \batch_example_op_1()
  3. 3.x modules/batch_example/batch_example.module \batch_example_op_1()

Batch operation for batch 1: one at a time.

This is the function that is called on each operation in batch 1.

Related topics

1 string reference to 'batch_example_op_1'
BatchExampleForm::generateBatch1 in batch_example/src/Form/BatchExampleForm.php
Generate Batch 1.

File

batch_example/batch_example.module, line 36
Outlines how a module can use the Batch API.

Code

function batch_example_op_1($id, $operation_details, &$context) {

  // Simulate long process by waiting 1/50th of a second.
  usleep(20000);

  // Store some results for post-processing in the 'finished' callback.
  // The contents of 'results' will be available as $results in the
  // 'finished' function (in this example, batch_example_finished()).
  $context['results'][] = $id;

  // Optional message displayed under the progressbar.
  $context['message'] = t('Running Batch "@id" @details', [
    '@id' => $id,
    '@details' => $operation_details,
  ]);
}