You are here

test_batch_test.install in Drupal 8

Install hooks for test module.

File

core/modules/system/tests/modules/test_batch_test/test_batch_test.install
View source
<?php

/**
 * @file
 * Install hooks for test module.
 */
use Drupal\entity_test\Entity\EntityTest;

/**
 * Implements hook_install().
 */
function test_batch_test_install() {
  $total = 2;
  $operations = [];
  for ($i = 1; $i <= $total; $i++) {
    $operations[] = [
      '_test_batch_test_callback',
      [
        $i,
      ],
    ];
  }
  $batch = [
    'operations' => $operations,
  ];
  batch_set($batch);
  $batch =& batch_get();
  $batch['progressive'] = FALSE;
  batch_process();
}

/**
 * Callback for batch operations.
 */
function _test_batch_test_callback($id) {
  $entity = EntityTest::create([
    'id' => $id,
  ]);
  $entity
    ->save();
}

Functions

Namesort descending Description
test_batch_test_install Implements hook_install().
_test_batch_test_callback Callback for batch operations.