Skip to content

Commit 129a05f

Browse files
authored
[5.2] Jooa11y plugin and page cache conflicts (#41956)
1 parent 8141452 commit 129a05f

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

plugins/system/jooa11y/src/Extension/Jooa11y.php

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

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

13+
use Joomla\CMS\Event\PageCache\SetCachingEvent;
14+
use Joomla\CMS\Factory;
1315
use Joomla\CMS\Plugin\CMSPlugin;
16+
use Joomla\Event\Priority;
1417
use Joomla\Event\SubscriberInterface;
1518

1619
// phpcs:disable PSR1.Files.SideEffects
@@ -35,7 +38,11 @@ final class Jooa11y extends CMSPlugin implements SubscriberInterface
3538
*/
3639
public static function getSubscribedEvents(): array
3740
{
38-
return ['onBeforeCompileHead' => 'initJooa11y'];
41+
if (Factory::getApplication()->isClient('site')) {
42+
return ['onAfterRoute' => ['initJooa11y', Priority::HIGH]];
43+
}
44+
45+
return [];
3946
}
4047

4148
/**
@@ -49,10 +56,12 @@ private function isAuthorisedDisplayChecker(): bool
4956
{
5057
static $result;
5158

52-
if (\is_bool($result)) {
59+
if ($result !== null) {
5360
return $result;
5461
}
5562

63+
$result = true;
64+
5665
// If the user is not allowed to view the output then end here.
5766
$filterGroups = (array) $this->params->get('filter_groups', []);
5867

@@ -63,27 +72,21 @@ private function isAuthorisedDisplayChecker(): bool
6372

6473
if (!array_intersect($filterGroups, $userGroups)) {
6574
$result = false;
66-
return $result;
6775
}
6876
}
6977

70-
$result = true;
7178
return $result;
7279
}
7380

7481
/**
75-
* Add the checker.
82+
* Init the checker.
7683
*
7784
* @return void
7885
*
7986
* @since 4.1.0
8087
*/
8188
public function initJooa11y()
8289
{
83-
if (!$this->getApplication()->isClient('site')) {
84-
return;
85-
}
86-
8790
// Check if we are in a preview modal or the plugin has enforced loading
8891
$showJooa11y = $this->getApplication()
8992
->getInput()
@@ -94,6 +97,27 @@ public function initJooa11y()
9497
return;
9598
}
9699

100+
// Disable page cache
101+
$this->getDispatcher()->addListener(
102+
'onPageCacheSetCaching',
103+
static function (SetCachingEvent $event) {
104+
$event->addResult(false);
105+
}
106+
);
107+
108+
// Register own event to add the checker later, once a document is created
109+
$this->getDispatcher()->addListener('onBeforeCompileHead', [$this, 'addJooa11y']);
110+
}
111+
112+
/**
113+
* Add the checker.
114+
*
115+
* @return void
116+
*
117+
* @since __DEPLOY_VERSION__
118+
*/
119+
public function addJooa11y()
120+
{
97121
// Load translations
98122
$this->loadLanguage();
99123

@@ -152,6 +176,7 @@ public function initJooa11y()
152176
}
153177

154178
// Get the document object
179+
/** @var \Joomla\CMS\Document\HtmlDocument $document */
155180
$document = $this->getApplication()->getDocument();
156181

157182
// Get plugin options from xml

0 commit comments

Comments
 (0)