You are here

public function UserPasswordForm::submitForm in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/user/src/Form/UserPasswordForm.php \Drupal\user\Form\UserPasswordForm::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

core/modules/user/src/Form/UserPasswordForm.php, line 178

Class

UserPasswordForm
Provides a user password reset form.

Namespace

Drupal\user\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $langcode = $this->languageManager
    ->getCurrentLanguage()
    ->getId();
  $account = $form_state
    ->getValue('account');

  // Mail one time login URL and instructions using current language.
  $mail = _user_mail_notify('password_reset', $account, $langcode);
  if (!empty($mail)) {
    $this
      ->logger('user')
      ->notice('Password reset instructions mailed to %name at %email.', [
      '%name' => $account
        ->getAccountName(),
      '%email' => $account
        ->getEmail(),
    ]);
    $this
      ->messenger()
      ->addStatus($this
      ->t('Further instructions have been sent to your email address.'));
  }
  $form_state
    ->setRedirect('user.page');
}