1

Can anyone explain or point me to information on the new way to handle events in Joomla 4? I'm updating a component that uses triggers to display plugins, and it looks like this:

$dispatcher = JEventDispatcher::getInstance();
$dispatcher->trigger('onBeforeRenderToolbar', array($settings));

In Joomla 4 this throws an error that there's no JEventDispatcher class-- but the new Joomla\Event\Dispatcher stuff doesn't make much sense to me and doesn't seem to have the same methods. The docs at https://docs.joomla.org/Supporting_plugins_in_your_component have not been updated to support the new syntax.

Thanks for any help.

2
use Joomla\CMS\Factory;

Factory::getApplication()->triggerEvent('onBeforeRenderToolbar', array($settings));

This method can be used in 3.x too.

  • Thanks Sharky. I couldn't find any namepsaced class for JEventDispatcher in the classmap so was wondering for a moment whether to stick with it, or if there was another approach. – Lodder Oct 17 at 8:00

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.