function UserLoginForm::buildForm
Same name in other branches
- 8.9.x core/modules/user/src/Form/UserLoginForm.php \Drupal\user\Form\UserLoginForm::buildForm()
- 10 core/modules/user/src/Form/UserLoginForm.php \Drupal\user\Form\UserLoginForm::buildForm()
- 11.x core/modules/user/src/Form/UserLoginForm.php \Drupal\user\Form\UserLoginForm::buildForm()
Overrides FormInterface::buildForm
File
-
core/
modules/ user/ src/ Form/ UserLoginForm.php, line 111
Class
- UserLoginForm
- Provides a user login form.
Namespace
Drupal\user\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('system.site');
// Display login form:
$form['name'] = [
'#type' => 'textfield',
'#title' => $this->t('Username'),
'#size' => 60,
'#maxlength' => UserInterface::USERNAME_MAX_LENGTH,
'#description' => $this->t('Enter your @s username.', [
'@s' => $config->get('name'),
]),
'#required' => TRUE,
'#attributes' => [
'autocorrect' => 'none',
'autocapitalize' => 'none',
'spellcheck' => 'false',
'autofocus' => 'autofocus',
],
];
$form['pass'] = [
'#type' => 'password',
'#title' => $this->t('Password'),
'#size' => 60,
'#description' => $this->t('Enter the password that accompanies your username.'),
'#required' => TRUE,
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Log in'),
];
$form['#validate'][] = '::validateName';
$form['#validate'][] = '::validateAuthentication';
$form['#validate'][] = '::validateFinal';
$this->renderer
->addCacheableDependency($form, $config);
return $form;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.