You are here

public function SwitchUserForm::validateForm in Devel 8

Same name and namespace in other branches
  1. 8.3 src/Form/SwitchUserForm.php \Drupal\devel\Form\SwitchUserForm::validateForm()
  2. 8.2 src/Form/SwitchUserForm.php \Drupal\devel\Form\SwitchUserForm::validateForm()
  3. 4.x src/Form/SwitchUserForm.php \Drupal\devel\Form\SwitchUserForm::validateForm()

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/SwitchUserForm.php, line 86

Class

SwitchUserForm
Defines a form that allows privileged users to generate entities.

Namespace

Drupal\devel\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  if (!($account = User::load($form_state
    ->getValue('userid')))) {
    $form_state
      ->setErrorByName('userid', $this
      ->t('Username not found'));
  }
  else {
    $form_state
      ->setValue('username', $account
      ->getAccountName());
  }
}