I am looking for ways to trigger an event in my local dev to check out a custom event subscriber. The actual event is triggered by Google social auth and I don't think it is possible to do that locally.

Is it possible to trigger events using devel


You can use the event_dispatcher service to trigger an event.

Use this code to trigger your event.

\Drupal::service('event_dispatcher')->dispatch(MyModuleEvents::MY_EVENT, new MyModuleEventClass());

Of course you have to replace the names with your real names.

You can run the code using drush php.

You can read more about subscribing and dispatching events here.

  • How do we pass arguments to the MyModuleEventClass in the drush cmd? Can we run a PHP file directly?
    – Binny
    Jan 3 '20 at 12:31
  • 2
    You can write the code in a custom module in the .module file. So if you create a function called my_module_dispatch, you can run my_module_dispatch()` in drush php.
    – user72672
    Jan 3 '20 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.