You are here

public function BulkAddCasUsers::submitForm in CAS 8

Same name and namespace in other branches
  1. 2.x src/Form/BulkAddCasUsers.php \Drupal\cas\Form\BulkAddCasUsers::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/BulkAddCasUsers.php, line 84

Class

BulkAddCasUsers
Class BulkAddCasUsers.

Namespace

Drupal\cas\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $roles = array_filter($form_state
    ->getValue('roles'));
  unset($roles[RoleInterface::AUTHENTICATED_ID]);
  $roles = array_keys($roles);
  $cas_usernames = trim($form_state
    ->getValue('cas_usernames'));
  $cas_usernames = preg_split('/[\\n\\r|\\r|\\n]+/', $cas_usernames);
  $email_hostname = trim($form_state
    ->getValue('email_hostname'));
  $operations = [];
  foreach ($cas_usernames as $cas_username) {
    $cas_username = trim($cas_username);
    if (!empty($cas_username)) {
      $operations[] = [
        '\\Drupal\\cas\\Form\\BulkAddCasUsers::userAdd',
        [
          $cas_username,
          $roles,
          $email_hostname,
        ],
      ];
    }
  }
  $batch = [
    'title' => $this
      ->t('Creating CAS users...'),
    'operations' => $operations,
    'finished' => '\\Drupal\\cas\\Form\\BulkAddCasUsers::userAddFinished',
    'progress_message' => $this
      ->t('Processed @current out of @total.'),
  ];
  batch_set($batch);
}