function EventsExampleForm::buildForm

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

Overrides FormInterface::buildForm

File

modules/events_example/src/Form/EventsExampleForm.php, line 63

Class

EventsExampleForm
Implements the SimpleForm form controller.

Namespace

Drupal\events_example\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
    $form['intro'] = [
        '#markup' => '<p>' . $this->t('This form demonstrates subscribing to, and dispatching, events. When the form is submitted an event is dispatched indicating a new report has been submitted. Event subscribers respond to this event with various messages depending on the incident type. Review the code for the events_example module to see how it works.') . '</p>',
    ];
    $form['incident_type'] = [
        '#type' => 'radios',
        '#required' => TRUE,
        '#title' => $this->t('What type of incident do you want to report?'),
        '#options' => [
            'stolen_princess' => $this->t('Missing princess'),
            'cat' => $this->t('Cat stuck in tree'),
            'joker' => $this->t('Something involving the Joker'),
        ],
    ];
    $form['incident'] = [
        '#type' => 'textarea',
        '#required' => FALSE,
        '#title' => $this->t('Incident report'),
        '#description' => $this->t('Describe the incident in detail. This information will be passed along to all crime fighters.'),
        '#cols' => 60,
        '#rows' => 5,
    ];
    $form['actions'] = [
        '#type' => 'actions',
    ];
    $form['actions']['submit'] = [
        '#type' => 'submit',
        '#value' => $this->t('Submit'),
    ];
    return $form;
}