You are here

public function BasicDisable::submitForm in Two-factor Authentication (TFA) 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/BasicDisable.php, line 181

Class

BasicDisable
TFA disable form router.

Namespace

Drupal\tfa\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $storage = $form_state
    ->getStorage();
  $values = $form_state
    ->getValues();
  $account = $storage['account'];
  if ($values['op'] === $values['cancel']) {
    $this
      ->messenger()
      ->addStatus($this
      ->t('TFA disable cancelled.'));
    $form_state
      ->setRedirect('tfa.overview', [
      'user' => $account
        ->id(),
    ]);
    return;
  }

  // Delete all user data.
  $this
    ->deleteUserData('tfa', NULL, $account
    ->id(), $this->userData);
  $this
    ->logger('tfa')
    ->notice('TFA disabled for user @name UID @uid', [
    '@name' => $account
      ->getAccountName(),
    '@uid' => $account
      ->id(),
  ]);

  // E-mail account to inform user that it has been disabled.
  $params = [
    'account' => $account,
  ];
  $this->mailManager
    ->mail('tfa', 'tfa_disabled_configuration', $account
    ->getEmail(), $account
    ->getPreferredLangcode(), $params);
  $this
    ->messenger()
    ->addStatus($this
    ->t('TFA has been disabled.'));
  $form_state
    ->setRedirect('tfa.overview', [
    'user' => $account
      ->id(),
  ]);
}