test_batch_test.install

Same filename in other branches
  1. 9 core/modules/system/tests/modules/test_batch_test/test_batch_test.install
  2. 8.9.x core/modules/system/tests/modules/test_batch_test/test_batch_test.install
  3. 11.x core/modules/system/tests/modules/test_batch_test/test_batch_test.install

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

Title Deprecated Summary
test_batch_test_install Implements hook_install().
_test_batch_test_callback Callback for batch operations.

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