function SwitchUserForm::validateForm
Same name in other branches
- 4.x src/Form/SwitchUserForm.php \Drupal\devel\Form\SwitchUserForm::validateForm()
Overrides FormBase::validateForm
File
-
src/
Form/ SwitchUserForm.php, line 82
Class
- SwitchUserForm
- Define a form to allow the user to switch and become another user.
Namespace
Drupal\devel\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) : void {
$userId = $form_state->getValue('userid');
if ($userId === NULL) {
$form_state->setErrorByName('userid', $this->t('Username not found'));
return;
}
/** @var \Drupal\user\UserInterface|null $account */
$account = $this->userStorage
->load($userId);
if ($account === NULL) {
$form_state->setErrorByName('userid', $this->t('Username not found'));
}
else {
$form_state->setValue('username', $account->getAccountName());
}
}