You are here

public function MassPasswordChangeConfirm::submitForm in Mass Password Change 8

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/MassPasswordChangeConfirm.php, line 123

Class

MassPasswordChangeConfirm
Provides a confirmation form for mass password change action.

Namespace

Drupal\mass_password_change\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // Clear out the accounts from the temp store.
  $this->tempStoreFactory
    ->get('mass_password_change')
    ->delete('password_change');
  if ($form_state
    ->getValue('confirm')) {
    $password = $form_state
      ->getValue('password');
    foreach ($form_state
      ->getValue('accounts') as $uid) {

      /* @var \Drupal\user\Entity\User $account */
      $account = $this->userStorage
        ->load($uid);
      $account
        ->setPassword($password);
      $account
        ->save();
    }
  }
  $form_state
    ->setRedirect('entity.user.collection');
}