Skip to content

Commit 6dd79ee

Browse files
Fediklaoneo
andauthored
[5.3] [Events] Use event classes for System plugins (#43637)
* system Accessibility * system Accessibility * system ActionLogs * system fields * system highlight * system Jooa11y * system Jooa11y * system LanguageCode * system ActionLogs * system ActionLogs * system log * system logout * system PrivacyConsent * system Remember * system Remember * system Skipto * system stats * system log * fields fix * cs * update * cs * update * update --------- Co-authored-by: Allon Moritz <[email protected]>
1 parent 00afe74 commit 6dd79ee

File tree

19 files changed

+567
-224
lines changed

19 files changed

+567
-224
lines changed

libraries/src/Event/CoreEventAware.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ trait CoreEventAware
9090
'onSchemaPrepareData' => Plugin\System\Schemaorg\PrepareDataEvent::class,
9191
'onSchemaPrepareForm' => Plugin\System\Schemaorg\PrepareFormEvent::class,
9292
'onSchemaPrepareSave' => Plugin\System\Schemaorg\PrepareSaveEvent::class,
93+
// Plugin: Stats
94+
'onGetStatsData' => Plugin\System\Stats\GetStatsDataEvent::class,
9395
// Content
9496
'onContentPrepare' => Content\ContentPrepareEvent::class,
9597
'onContentAfterTitle' => Content\AfterTitleEvent::class,
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
/**
4+
* Joomla! Content Management System
5+
*
6+
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
7+
* @license GNU General Public License version 2 or later; see LICENSE.txt
8+
*/
9+
10+
namespace Joomla\CMS\Event\Plugin\System\Stats;
11+
12+
use Joomla\CMS\Event\AbstractImmutableEvent;
13+
use Joomla\CMS\Event\ReshapeArgumentsAware;
14+
use Joomla\CMS\Event\Result\ResultAware;
15+
use Joomla\CMS\Event\Result\ResultAwareInterface;
16+
use Joomla\CMS\Event\Result\ResultTypeArrayAware;
17+
18+
// phpcs:disable PSR1.Files.SideEffects
19+
\defined('_JEXEC') or die;
20+
// phpcs:enable PSR1.Files.SideEffects
21+
22+
/**
23+
* Class for Stats plugin.
24+
* Example:
25+
* new GetStatsDataEvent('onEventName', ['context' => 'com_example.example']);
26+
*
27+
* @since __DEPLOY_VERSION__
28+
*/
29+
class GetStatsDataEvent extends AbstractImmutableEvent implements ResultAwareInterface
30+
{
31+
use ReshapeArgumentsAware;
32+
use ResultAware;
33+
use ResultTypeArrayAware;
34+
35+
/**
36+
* The argument names, in order expected by legacy plugins.
37+
*
38+
* @var array
39+
*
40+
* @since __DEPLOY_VERSION__
41+
* @deprecated __DEPLOY_VERSION__ will be removed in 6.0
42+
*/
43+
protected $legacyArgumentsOrder = ['context'];
44+
45+
/**
46+
* Constructor.
47+
*
48+
* @param string $name The event name.
49+
* @param array $arguments The event arguments.
50+
*
51+
* @throws \BadMethodCallException
52+
*
53+
* @since __DEPLOY_VERSION__
54+
*/
55+
public function __construct($name, array $arguments = [])
56+
{
57+
// Reshape the arguments array to preserve b/c with legacy listeners
58+
if ($this->legacyArgumentsOrder) {
59+
$arguments = $this->reshapeArguments($arguments, $this->legacyArgumentsOrder);
60+
}
61+
62+
parent::__construct($name, $arguments);
63+
64+
if (!\array_key_exists('context', $this->arguments)) {
65+
throw new \BadMethodCallException("Argument 'context' of event {$name} is required but has not been provided");
66+
}
67+
}
68+
69+
/**
70+
* Setter for the context argument.
71+
*
72+
* @param string $value The value to set
73+
*
74+
* @return string
75+
*
76+
* @since __DEPLOY_VERSION__
77+
*/
78+
protected function onSetContext(string $value): string
79+
{
80+
return $value;
81+
}
82+
83+
/**
84+
* Getter for the context argument.
85+
*
86+
* @return string
87+
*
88+
* @since __DEPLOY_VERSION__
89+
*/
90+
public function getContext(): string
91+
{
92+
return $this->arguments['context'];
93+
}
94+
}

plugins/system/accessibility/src/Extension/Accessibility.php

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
namespace Joomla\Plugin\System\Accessibility\Extension;
1212

13+
use Joomla\CMS\Event\Application\BeforeCompileHeadEvent;
1314
use Joomla\CMS\Plugin\CMSPlugin;
15+
use Joomla\Event\SubscriberInterface;
1416

1517
// phpcs:disable PSR1.Files.SideEffects
1618
\defined('_JEXEC') or die;
@@ -21,43 +23,60 @@
2123
*
2224
* @since 4.0.0
2325
*/
24-
final class Accessibility extends CMSPlugin
26+
final class Accessibility extends CMSPlugin implements SubscriberInterface
2527
{
28+
/**
29+
* Returns an array of events this subscriber will listen to.
30+
*
31+
* @return array
32+
*
33+
* @since __DEPLOY_VERSION__
34+
*/
35+
public static function getSubscribedEvents(): array
36+
{
37+
return [
38+
'onBeforeCompileHead' => 'onBeforeCompileHead',
39+
];
40+
}
41+
2642
/**
2743
* Add the javascript for the accessibility menu
2844
*
45+
* @param BeforeCompileHeadEvent $event The event object
46+
*
2947
* @return void
3048
*
3149
* @since 4.0.0
3250
*/
33-
public function onBeforeCompileHead()
51+
public function onBeforeCompileHead(BeforeCompileHeadEvent $event): void
3452
{
3553
$section = $this->params->get('section', 'administrator');
54+
$app = $event->getApplication();
3655

37-
if ($section !== 'both' && $this->getApplication()->isClient($section) !== true) {
56+
if ($section !== 'both' && $app->isClient($section) !== true) {
3857
return;
3958
}
4059

4160
// Get the document object.
42-
$document = $this->getApplication()->getDocument();
61+
$document = $event->getDocument();
4362

4463
if ($document->getType() !== 'html') {
4564
return;
4665
}
4766

4867
// Are we in a modal?
49-
if ($this->getApplication()->getInput()->get('tmpl', '', 'cmd') === 'component') {
68+
if ($app->getInput()->get('tmpl', '', 'cmd') === 'component') {
5069
return;
5170
}
5271

5372
// Load language file.
5473
$this->loadLanguage();
5574

5675
// Determine if it is an LTR or RTL language
57-
$direction = $this->getApplication()->getLanguage()->isRtl() ? 'right' : 'left';
76+
$direction = $app->getLanguage()->isRtl() ? 'right' : 'left';
5877

5978
// Detect the current active language
60-
$lang = $this->getApplication()->getLanguage()->getTag();
79+
$lang = $app->getLanguage()->getTag();
6180

6281
/**
6382
* Add strings for translations in Javascript.
@@ -67,20 +86,20 @@ public function onBeforeCompileHead()
6786
'accessibility-options',
6887
[
6988
'labels' => [
70-
'menuTitle' => $this->getApplication()->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_MENU_TITLE'),
71-
'increaseText' => $this->getApplication()->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_INCREASE_TEXT'),
72-
'decreaseText' => $this->getApplication()->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_DECREASE_TEXT'),
73-
'increaseTextSpacing' => $this->getApplication()->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_INCREASE_SPACING'),
74-
'decreaseTextSpacing' => $this->getApplication()->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_DECREASE_SPACING'),
75-
'invertColors' => $this->getApplication()->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_INVERT_COLORS'),
76-
'grayHues' => $this->getApplication()->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_GREY'),
77-
'underlineLinks' => $this->getApplication()->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_UNDERLINE'),
78-
'bigCursor' => $this->getApplication()->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_CURSOR'),
79-
'readingGuide' => $this->getApplication()->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_READING'),
80-
'textToSpeech' => $this->getApplication()->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_TTS'),
81-
'speechToText' => $this->getApplication()->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_STT'),
82-
'resetTitle' => $this->getApplication()->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_RESET'),
83-
'closeTitle' => $this->getApplication()->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_CLOSE'),
89+
'menuTitle' => $app->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_MENU_TITLE'),
90+
'increaseText' => $app->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_INCREASE_TEXT'),
91+
'decreaseText' => $app->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_DECREASE_TEXT'),
92+
'increaseTextSpacing' => $app->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_INCREASE_SPACING'),
93+
'decreaseTextSpacing' => $app->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_DECREASE_SPACING'),
94+
'invertColors' => $app->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_INVERT_COLORS'),
95+
'grayHues' => $app->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_GREY'),
96+
'underlineLinks' => $app->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_UNDERLINE'),
97+
'bigCursor' => $app->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_CURSOR'),
98+
'readingGuide' => $app->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_READING'),
99+
'textToSpeech' => $app->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_TTS'),
100+
'speechToText' => $app->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_STT'),
101+
'resetTitle' => $app->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_RESET'),
102+
'closeTitle' => $app->getLanguage()->_('PLG_SYSTEM_ACCESSIBILITY_CLOSE'),
84103
],
85104
'icon' => [
86105
'position' => [

0 commit comments

Comments
 (0)