diff --git a/libraries/src/Event/AbstractEvent.php b/libraries/src/Event/AbstractEvent.php index 4242d446b6bf8..f128ac8095995 100644 --- a/libraries/src/Event/AbstractEvent.php +++ b/libraries/src/Event/AbstractEvent.php @@ -140,6 +140,23 @@ public function __construct(string $name, array $arguments = []) */ public function getArgument($name, $default = null) { + // B/C check for numeric access to named argument, eg $event->getArgument('0'). + if (is_numeric($name)) { + if (key($this->arguments) != 0) { + $argNames = \array_keys($this->arguments); + $name = $argNames[$name] ?? ''; + } + + @trigger_error( + sprintf( + 'Numeric access to named event arguments is deprecated, and will not work in Joomla 6. Event %s argument %s', + \get_class($this), + $name + ), + E_USER_DEPRECATED + ); + } + $methodName = 'get' . ucfirst($name); $value = parent::getArgument($name, $default); @@ -170,6 +187,23 @@ public function getArgument($name, $default = null) */ public function setArgument($name, $value) { + // B/C check for numeric access to named argument, eg $event->setArgument('0', $value). + if (is_numeric($name)) { + if (key($this->arguments) != 0) { + $argNames = \array_keys($this->arguments); + $name = $argNames[$name] ?? ''; + } + + @trigger_error( + sprintf( + 'Numeric access to named event arguments is deprecated, and will not work in Joomla 6. Event %s argument %s', + \get_class($this), + $name + ), + E_USER_DEPRECATED + ); + } + $methodName = 'set' . ucfirst($name); if (method_exists($this, $methodName)) { diff --git a/libraries/src/Plugin/CMSPlugin.php b/libraries/src/Plugin/CMSPlugin.php index d9bfd5029f033..0f690e03c9243 100644 --- a/libraries/src/Plugin/CMSPlugin.php +++ b/libraries/src/Plugin/CMSPlugin.php @@ -10,6 +10,8 @@ namespace Joomla\CMS\Plugin; use Joomla\CMS\Application\CMSApplicationInterface; +use Joomla\CMS\Event\AbstractImmutableEvent; +use Joomla\CMS\Event\Result\ResultAwareInterface; use Joomla\CMS\Extension\PluginInterface; use Joomla\CMS\Factory; use Joomla\CMS\Language\LanguageAwareInterface; @@ -291,9 +293,13 @@ function (AbstractEvent $event) use ($methodName) { return; } - // Restore the old results and add the new result from our method call - $allResults[] = $result; - $event['result'] = $allResults; + if ($event instanceof ResultAwareInterface) { + $event->addResult($result); + } elseif (!$event instanceof AbstractImmutableEvent) { + // Restore the old results and add the new result from our method call + $allResults[] = $result; + $event['result'] = $allResults; + } } ); }