Example for how to dispatch an example event in Drupal 8?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Following is the example for How to dispatch an event in Drupal 8? | |
// Use the namespace of the ExampleEvent class | |
use Drupal\example_events\ExampleEvent; | |
// load the Symfony event dispatcher object through services | |
$dispatcher = \Drupal::service('event_dispatcher'); | |
// creating our event class object. | |
$event = new ExampleEvent($form_state->getValue('name')); | |
// dispatching the event through the ‘dispatch’ method, | |
// passing event name and event object ‘$event’ as parameters. | |
$dispatcher->dispatch(ExampleEvent::SUBMIT, $event); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment