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

You can use the event_dispatcherevent_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.

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.

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.

added 1 character in body
Source Link
user72672
user72672

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());.

\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.

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.

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.

Source Link
user72672
user72672

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.