29
0
mirror of https://github.com/joomla/joomla-cms.git synced 2024-06-16 09:02:52 +00:00

Events backward compatibility handling (#41357)

This commit is contained in:
Fedir Zinchuk 2023-08-14 13:57:27 +03:00 committed by GitHub
parent 60faae8b8d
commit fcc7209570
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 3 deletions

View File

@ -140,6 +140,23 @@ abstract class AbstractEvent extends BaseEvent
*/
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 @@ abstract class AbstractEvent extends BaseEvent
*/
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)) {

View File

@ -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 @@ abstract class CMSPlugin implements DispatcherAwareInterface, PluginInterface, L
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;
}
}
);
}