Skip to content

Instantly share code, notes, and snippets.

@kasvith
Last active July 20, 2019 15:51
Show Gist options
  • Save kasvith/1217c31414cfcece82fd5565b70ff80a to your computer and use it in GitHub Desktop.
Save kasvith/1217c31414cfcece82fd5565b70ff80a to your computer and use it in GitHub Desktop.
Joomla 4 Events

For anyone who is facing issue getting result from

$results = \JFactory::getApplication()->triggerEvent('onSomeEvent', $event);

If you gets an empty array every time do as follow.

In your plugin's onSomeEvent($event) do not return your result.

$event must implement Joomla\Event\EventInterface . Otherwise Legacy methods will trigger and you will get empty result. Please take a note of that.

In plugin

public function onSomeEvent(Joomla\Event\EventInterface $event)
{
     	// your code
	
	$result = $event->getArguments('result', []); // prevent overwriting existing results if any
	$result[] = 'your result';
	$event->setArguments('result', $result);
} 

This will return what you set in $result to the $results as an array. Do not use legacy return with J4.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment