You are here

public function SwitchUserForm::buildForm in Devel 8.3

Same name and namespace in other branches
  1. 8 src/Form/SwitchUserForm.php \Drupal\devel\Form\SwitchUserForm::buildForm()
  2. 8.2 src/Form/SwitchUserForm.php \Drupal\devel\Form\SwitchUserForm::buildForm()
  3. 4.x src/Form/SwitchUserForm.php \Drupal\devel\Form\SwitchUserForm::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

src/Form/SwitchUserForm.php, line 54

Class

SwitchUserForm
Define a form to allow the user to switch and become another user.

Namespace

Drupal\devel\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['autocomplete'] = [
    '#type' => 'container',
    '#attributes' => [
      'class' => [
        'container-inline',
      ],
    ],
  ];
  $form['autocomplete']['userid'] = [
    '#type' => 'entity_autocomplete',
    '#title' => $this
      ->t('Username'),
    '#placeholder' => $this
      ->t('Enter username'),
    '#target_type' => 'user',
    '#selection_settings' => [
      'include_anonymous' => FALSE,
    ],
    '#process_default_value' => FALSE,
    '#maxlength' => UserInterface::USERNAME_MAX_LENGTH,
    '#title_display' => 'invisible',
    '#required' => TRUE,
    '#size' => '28',
  ];
  $form['autocomplete']['actions'] = [
    '#type' => 'actions',
  ];
  $form['autocomplete']['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Switch'),
  ];
  return $form;
}