Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Example for how to dispatch an example event in Drupal 8?
// 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