public function SelectForm::buildForm in Examples for Developers 3.x
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
- modules/
theming_example/ src/ Form/ SelectForm.php, line 28
Class
- SelectForm
- A simple form that displays a select box and submit button.
Namespace
Drupal\theming_example\FormCode
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;
}