PHP
Joomla! 6
Joomla! 5
Joomla! 3 (Legacy)
Plugin
Advanced
Dispatch a Custom Plugin Event with the Event Dispatcher
Imports a plugin group and dispatches an extensible event object via $app->getDispatcher()->dispatch() in Joomla 5 and 6.
components/com_example/src/Model/ItemModel.php
<?php
declare(strict_types=1);
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Event\Event;
$app = Factory::getApplication();
PluginHelper::importPlugin('content');
$event = new Event('onExampleAfterProcess', [
'context' => 'com_example.item',
'item' => $item,
]);
$app->getDispatcher()->dispatch('onExampleAfterProcess', $event);
$results = $event->getArgument('result', []);
Read modified payloads back from $event->getArgument() after dispatch.
components/com_example/src/Model/ItemModel.php
<?php
JPluginHelper::importPlugin('content');
$dispatcher = JEventDispatcher::getInstance();
$results = $dispatcher->trigger('onExampleAfterProcess', array('com_example.item', &$item));
Legacy Joomla 3 syntax using JEventDispatcher::getInstance()->trigger().
Technical explanation and best practices
Make your custom component extensible to plugins in Joomla 5 and 6 by dispatching typed Event or GenericEvent instances via $app->getDispatcher()->dispatch() instead of legacy triggerEvent().