function SwitchUserForm::buildForm

Same name in other branches
  1. 4.x src/Form/SwitchUserForm.php \Drupal\devel\Form\SwitchUserForm::buildForm()
  2. 5.x src/Form/SwitchUserForm.php \Drupal\devel\Form\SwitchUserForm::buildForm()

File

src/Form/SwitchUserForm.php, line 52

Class

SwitchUserForm
Defines a form that allows privileged users to generate entities.

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