Skip to main content
3 of 3
improved formatting; Post Made Community Wiki
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

You can use the event_dispatcher service to trigger an event, for example with \Drupal::service('event_dispatcher')->dispatch(MyModuleEvents::MY_EVENT, new MyModuleEventClass());.

You need to replace MyModuleEvents and MyModuleEventClass with the class names you are effectively using, and MyModuleEvents::MY_EVENT with the effective event name. (It is better to use a class constant.)

You can run the code using drush php "\Drupal::service('event_dispatcher')->dispatch(MyModuleEvents::MY_EVENT, new MyModuleEventClass());".

See Subscribe to and dispatch events for more details.

user72672