Ordering of Event LIsteners

Is there a way to control the order in which 2 event listeners listening to the same event are handled?

I’m trying to extend a 3rd party plugin with my own plugin and both plugins have an event listener

Event::listen('cms.router.beforeRoute', function ($url) {
  //do stuff
}

which fetches some data to render a page. Currently their event listener fires first every time and I would like mine to fire first. Is there a way to achieve this?

Hi @zimple.digital,

You can control the execution order by setting a priority when subscribing to the event.

Check out the OctoberCMS docs for more details:

Note: After carefully reading your message, I understand that you can’t set the priority in the other plugin. In this case, you’d need to check its internal implementation to see how it handles event registration. Hopefully, the one without an explicit priority parameter runs last. Give it a try and see if that works.

HI @apinard,

Yes, that’s how it worked. After I added a priority value to my event listener it ran first even though the 3rd party plugin event listener didn’t have a priority value.