You are here

public function UserEmailVerificationRequestForm::validateForm in User email verification 8

Form validation 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 FormBase::validateForm

File

src/Form/UserEmailVerificationRequestForm.php, line 144

Class

UserEmailVerificationRequestForm
Class UserEmailVerificationRequestForm.

Namespace

Drupal\user_email_verification\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $name_or_email = trim($form_state
    ->getValue('name', ''));
  if ($name_or_email) {
    $active_users_only = $this->configUserSettings
      ->get('register') != UserInterface::REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL;
    $user = $this->userEmailVerification
      ->getUserByNameOrEmail($name_or_email, $active_users_only);
    if ($user instanceof UserInterface) {
      $form_state
        ->setValue('uid', $user
        ->id());
    }
    else {
      $form_state
        ->setErrorByName('name', $this
        ->t('Sorry, %name is not recognized as a user name or an Email address.', [
        '%name' => $name_or_email,
      ]));
    }
  }
}