function UserLoginForm::buildForm

Same name and namespace in other branches
  1. 9 core/modules/user/src/Form/UserLoginForm.php \Drupal\user\Form\UserLoginForm::buildForm()
  2. 8.9.x core/modules/user/src/Form/UserLoginForm.php \Drupal\user\Form\UserLoginForm::buildForm()
  3. 11.x 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 108

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,
    '#required' => TRUE,
    '#attributes' => [
      'autocorrect' => 'none',
      'autocapitalize' => 'none',
      'spellcheck' => 'false',
      'autofocus' => 'autofocus',
      'autocomplete' => 'username',
    ],
  ];
  $form['pass'] = [
    '#type' => 'password',
    '#title' => $this->t('Password'),
    '#size' => 60,
    '#required' => TRUE,
    '#attributes' => [
      'autocomplete' => 'current-password',
    ],
  ];
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this->t('Log in'),
  ];
  $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.