function SelectForm::buildForm

Same name in other branches
  1. 4.0.x modules/theming_example/src/Form/SelectForm.php \Drupal\theming_example\Form\SelectForm::buildForm()

Overrides FormInterface::buildForm

File

modules/theming_example/src/Form/SelectForm.php, line 26

Class

SelectForm
A simple form that displays a select box and submit button.

Namespace

Drupal\theming_example\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
    $options = [
        'newest_first' => $this->t('Newest first'),
        'newest_last' => $this->t('Newest last'),
        'edited_first' => $this->t('Edited first'),
        'edited_last' => $this->t('Edited last'),
        'by_name' => $this->t('By name'),
    ];
    $form['choice'] = [
        '#type' => 'select',
        '#options' => $options,
        '#title' => $this->t('Choose which ordering you want'),
    ];
    $form['submit'] = [
        '#type' => 'submit',
        '#value' => $this->t('Go'),
    ];
    return $form;
}