You are here

public function EventsExampleForm::buildForm in Examples for Developers 8

Same name and namespace in other branches
  1. 3.x modules/events_example/src/Form/EventsExampleForm.php \Drupal\events_example\Form\EventsExampleForm::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

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