You are here

public function ConfirmationForm::submitForm in Auto Purge Users 8

Same name and namespace in other branches
  1. 8.3 src/Form/ConfirmationForm.php \Drupal\purge_users\Form\ConfirmationForm::submitForm()
  2. 8.2 src/Form/ConfirmationForm.php \Drupal\purge_users\Form\ConfirmationForm::submitForm()

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

src/Form/ConfirmationForm.php, line 89

Class

ConfirmationForm
Class ConfirmationForm.

Namespace

Drupal\purge_users\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $ids = purge_users_get_user_ids();

  // Initialize a batch operation.
  $batch = array(
    'operations' => array(),
    'finished' => 'purge_users_batch_completed',
    'title' => $this
      ->t('Delete users'),
    'init_message' => $this
      ->t('Delete users operation is starting...'),
    'progress_message' => $this
      ->t('Processed @current out of @total.'),
    'error_message' => $this
      ->t('Delete users operation has encountered an error.'),
  );

  // User load multiple to process through batch operation.
  $results = User::loadMultiple($ids);
  foreach ($results as $result) {
    $batch['operations'][] = array(
      '\\Drupal\\purge_users\\Plugin\\BatchWorker\\BatchWorker::batchworkerpurgeusers',
      array(
        $result,
      ),
    );
  }

  // Batch set.
  batch_set($batch);
}