You can use the event_dispatcher
event_dispatcher service to trigger an event.
Use this code to trigger your event, for example with \Drupal::service('event_dispatcher')->dispatch(MyModuleEvents::MY_EVENT, new MyModuleEventClass());
.
\Drupal::service('event_dispatcher')->dispatch(MyModuleEvents::MY_EVENT, new MyModuleEventClass());
Of course you haveYou need to replace MyModuleEvents
and MyModuleEventClass
with the class names you are effectively using, and MyModuleEvents::MY_EVENT
with your real namesthe 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());"
.
You can read more aboutSee subscribingSubscribe to and dispatchingdispatch events here for more details.