function EventsExampleForm::submitForm
Same name in other branches
- 8.x-1.x events_example/src/Form/EventsExampleForm.php \Drupal\events_example\Form\EventsExampleForm::submitForm()
- 4.0.x modules/events_example/src/Form/EventsExampleForm.php \Drupal\events_example\Form\EventsExampleForm::submitForm()
Overrides FormInterface::submitForm
File
-
modules/
events_example/ src/ Form/ EventsExampleForm.php, line 110
Class
- EventsExampleForm
- Implements the SimpleForm form controller.
Namespace
Drupal\events_example\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$type = $form_state->getValue('incident_type');
$report = $form_state->getValue('incident');
// When dispatching, or triggering, an event start by constructing a new
// event object. Then use the event dispatcher service to notify any event
// subscribers. Event objects are used to transport relevant data to any
// subscribers, as well as keep track of the current state of an event. It
// is best practice to create a unique class wrapping
// \Symfony\Component\EventDispatcher\Event.
$event = new IncidentReportEvent($type, $report);
// Dispatch an event by specifying which event, and providing an event
// object. Rather than hard code the event name you should use a constant
// to represent the event being dispatched. The constant serves as a
// location for documentation of the event, and ensures your code is future
// proofed against event name changes.
$this->eventDispatcher
->dispatch($event, IncidentEvents::NEW_REPORT);
}