You are here

public function UserLoginForm::buildForm in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/user/src/Form/UserLoginForm.php \Drupal\user\Form\UserLoginForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

core/modules/user/src/Form/UserLoginForm.php, line 96

Class

UserLoginForm
Provides a user login form.

Namespace

Drupal\user\Form

Code

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;
}