You are here

public function SettingsForm::setBatch in Opigno Moxtra 8

Same name and namespace in other branches
  1. 3.x src/Form/SettingsForm.php \Drupal\opigno_moxtra\Form\SettingsForm::setBatch()

Set the batch.

1 call to SettingsForm::setBatch()
SettingsForm::registerAllSubmit in src/Form/SettingsForm.php

File

src/Form/SettingsForm.php, line 322

Class

SettingsForm
Implements the Opigno Moxtra settings form.

Namespace

Drupal\opigno_moxtra\Form

Code

public function setBatch() {
  $database = \Drupal::database();
  $query = $database
    ->select('users', 'u');
  $query
    ->fields('u', [
    'uid',
  ]);
  $users = $query
    ->execute()
    ->fetchAll();
  $batch_builder = (new BatchBuilder())
    ->setTitle($this
    ->t('Register Moxtra users'))
    ->setFinishCallback([
    $this,
    'finishBatch',
  ]);
  foreach ($users as $key => $user) {
    $batch_builder
      ->addOperation([
      $this,
      'processItem',
    ], [
      'users' => $user,
    ]);
  }
  batch_set($batch_builder
    ->toArray());
}