From b5f37db462e3489e3305306f6364db9f52a913be Mon Sep 17 00:00:00 2001 From: Fedik Date: Tue, 1 Aug 2023 19:21:02 +0300 Subject: [PATCH 1/2] b/c for get/set arguments --- libraries/src/Event/AbstractEvent.php | 34 +++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/libraries/src/Event/AbstractEvent.php b/libraries/src/Event/AbstractEvent.php index 8177d1cadd94c..ae1637ad26d36 100644 --- a/libraries/src/Event/AbstractEvent.php +++ b/libraries/src/Event/AbstractEvent.php @@ -137,6 +137,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); @@ -167,6 +184,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)) { From b226a6b871e1ff22053a283ed9eb69ea5f44acc8 Mon Sep 17 00:00:00 2001 From: Fedik Date: Thu, 10 Aug 2023 14:34:01 +0300 Subject: [PATCH 2/2] Fix legacy listeners to work with Immutable Event --- libraries/src/Plugin/CMSPlugin.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libraries/src/Plugin/CMSPlugin.php b/libraries/src/Plugin/CMSPlugin.php index 01cdc625bf483..9224af708c53a 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; + } } ); }