Skip to content

Commit

Permalink
[5.2] Jooa11y plugin and page cache conflicts (#41956)
Browse files Browse the repository at this point in the history
  • Loading branch information
Denitz authored Jan 19, 2025
1 parent 8141452 commit 129a05f
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions plugins/system/jooa11y/src/Extension/Jooa11y.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

namespace Joomla\Plugin\System\Jooa11y\Extension;

use Joomla\CMS\Event\PageCache\SetCachingEvent;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Event\Priority;
use Joomla\Event\SubscriberInterface;

// phpcs:disable PSR1.Files.SideEffects
Expand All @@ -35,7 +38,11 @@ final class Jooa11y extends CMSPlugin implements SubscriberInterface
*/
public static function getSubscribedEvents(): array
{
return ['onBeforeCompileHead' => 'initJooa11y'];
if (Factory::getApplication()->isClient('site')) {
return ['onAfterRoute' => ['initJooa11y', Priority::HIGH]];
}

return [];
}

/**
Expand All @@ -49,10 +56,12 @@ private function isAuthorisedDisplayChecker(): bool
{
static $result;

if (\is_bool($result)) {
if ($result !== null) {
return $result;
}

$result = true;

// If the user is not allowed to view the output then end here.
$filterGroups = (array) $this->params->get('filter_groups', []);

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

if (!array_intersect($filterGroups, $userGroups)) {
$result = false;
return $result;
}
}

$result = true;
return $result;
}

/**
* Add the checker.
* Init the checker.
*
* @return void
*
* @since 4.1.0
*/
public function initJooa11y()
{
if (!$this->getApplication()->isClient('site')) {
return;
}

// Check if we are in a preview modal or the plugin has enforced loading
$showJooa11y = $this->getApplication()
->getInput()
Expand All @@ -94,6 +97,27 @@ public function initJooa11y()
return;
}

// Disable page cache
$this->getDispatcher()->addListener(
'onPageCacheSetCaching',
static function (SetCachingEvent $event) {
$event->addResult(false);
}
);

// Register own event to add the checker later, once a document is created
$this->getDispatcher()->addListener('onBeforeCompileHead', [$this, 'addJooa11y']);
}

/**
* Add the checker.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function addJooa11y()
{
// Load translations
$this->loadLanguage();

Expand Down Expand Up @@ -152,6 +176,7 @@ public function initJooa11y()
}

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

// Get plugin options from xml
Expand Down

0 comments on commit 129a05f

Please sign in to comment.