Skip to content

Commit 98f3ecd

Browse files
committed
RegisterListenersChecker
1 parent 27a1218 commit 98f3ecd

File tree

4 files changed

+17
-31
lines changed

4 files changed

+17
-31
lines changed

libraries/src/Event/RegisterListenersCheckerInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @since __DEPLOY_VERSION__
2020
*/
21-
interface RegisterListenersCheckerInterface
21+
interface SubscriberRegistrationCheckerInterface
2222
{
2323
/**
2424
* Check whether the Subscriber (or event listener) should be registered.

libraries/src/Plugin/PluginHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace Joomla\CMS\Plugin;
1111

1212
use Joomla\CMS\Cache\Exception\CacheExceptionInterface;
13-
use Joomla\CMS\Event\RegisterListenersCheckerInterface;
13+
use Joomla\CMS\Event\SubscriberRegistrationCheckerInterface;
1414
use Joomla\CMS\Factory;
1515
use Joomla\Event\DispatcherAwareInterface;
1616
use Joomla\Event\DispatcherInterface;
@@ -241,7 +241,7 @@ protected static function import($plugin, $autocreate = true, DispatcherInterfac
241241
}
242242

243243
// Check whether we should register the subscriber in current runtime
244-
if ($plugin instanceof RegisterListenersCheckerInterface && !$plugin->shouldRegisterListeners()) {
244+
if ($plugin instanceof SubscriberRegistrationCheckerInterface && !$plugin->shouldRegisterListeners()) {
245245
dump($plugin);
246246
return;
247247
}

plugins/system/guidedtours/services/provider.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ function (Container $container) {
3939
$plugin = new GuidedTours(
4040
$container->get(DispatcherInterface::class),
4141
(array) PluginHelper::getPlugin('system', 'guidedtours'),
42-
$app->isClient('administrator')
4342
);
4443

4544
$plugin->setApplication($app);

plugins/system/guidedtours/src/Extension/GuidedTours.php

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

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

13+
use Joomla\CMS\Event\SubscriberRegistrationCheckerInterface;
1314
use Joomla\CMS\Language\Text;
1415
use Joomla\CMS\Object\CMSObject;
1516
use Joomla\CMS\Plugin\CMSPlugin;
1617
use Joomla\CMS\Session\Session;
1718
use Joomla\Component\Guidedtours\Administrator\Extension\GuidedtoursComponent;
1819
use Joomla\Component\Guidedtours\Administrator\Model\TourModel;
19-
use Joomla\Event\DispatcherInterface;
2020
use Joomla\Event\Event;
2121
use Joomla\Event\SubscriberInterface;
2222

@@ -29,7 +29,7 @@
2929
*
3030
* @since 4.3.0
3131
*/
32-
final class GuidedTours extends CMSPlugin implements SubscriberInterface
32+
final class GuidedTours extends CMSPlugin implements SubscriberInterface, SubscriberRegistrationCheckerInterface
3333
{
3434
/**
3535
* A mapping for the step types
@@ -59,43 +59,30 @@ final class GuidedTours extends CMSPlugin implements SubscriberInterface
5959
];
6060

6161
/**
62-
* An internal flag whether plugin should listen any event.
63-
*
64-
* @var bool
65-
*
66-
* @since 4.3.0
67-
*/
68-
protected static $enabled = false;
69-
70-
/**
71-
* Constructor
62+
* function for getSubscribedEvents : new Joomla 4 feature
7263
*
73-
* @param DispatcherInterface $dispatcher The object to observe
74-
* @param array $config An optional associative array of configuration settings.
75-
* @param boolean $enabled An internal flag whether plugin should listen any event.
64+
* @return array
7665
*
7766
* @since 4.3.0
7867
*/
79-
public function __construct(DispatcherInterface $dispatcher, array $config = [], bool $enabled = false)
68+
public static function getSubscribedEvents(): array
8069
{
81-
self::$enabled = $enabled;
82-
83-
parent::__construct($dispatcher, $config);
70+
return [
71+
'onAjaxGuidedtours' => 'startTour',
72+
'onBeforeCompileHead' => 'onBeforeCompileHead',
73+
];
8474
}
8575

8676
/**
87-
* function for getSubscribedEvents : new Joomla 4 feature
77+
* Check whether the Subscriber should be registered.
8878
*
89-
* @return array
79+
* @return bool
9080
*
91-
* @since 4.3.0
81+
* @since __DEPLOY_VERSION__
9282
*/
93-
public static function getSubscribedEvents(): array
83+
public function shouldRegisterListeners(): bool
9484
{
95-
return self::$enabled ? [
96-
'onAjaxGuidedtours' => 'startTour',
97-
'onBeforeCompileHead' => 'onBeforeCompileHead',
98-
] : [];
85+
return $this->getApplication()->isClient('administrator');
9986
}
10087

10188
/**

0 commit comments

Comments
 (0)