function BatchTestCallbacks::callback9

Same name and namespace in other branches
  1. 11.x core/modules/system/tests/modules/batch_test/src/BatchTestCallbacks.php \Drupal\batch_test\BatchTestCallbacks::callback9()

Implements callback_batch_operation().

Performs a simple batch operation.

File

core/modules/system/tests/modules/batch_test/src/BatchTestCallbacks.php, line 135

Class

BatchTestCallbacks
Batch callbacks for testing batches.

Namespace

Drupal\batch_test

Code

public function callback9(array &$context) : void {
  if (!isset($context['sandbox']['count'])) {
    $context['sandbox']['count'] = 0;
  }
  // No-op, but ensure the batch takes a couple iterations.
  // Batch needs time to run for the test, so sleep a bit.
  usleep(500);
  $context['sandbox']['count']++;
  $context['finished'] = $context['sandbox']['count'] / 5;
  $context['results'][] = \Drupal::request()->getUri();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.