From 8264969c613dfc3af5d0dd0bc27372c171a27c86 Mon Sep 17 00:00:00 2001 From: Marcel Kapfer Date: Sat, 6 May 2023 12:55:57 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Use=20Context=20API=20to=20check=20?= =?UTF-8?q?for=20logged=20in=20backend=20user?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `isBackendUserLoggedIn()` function of the TSFE array is deprecated starting with TYPO3 v12 and since the Context API also provides the necssary aspect and functionality in v11 there is no harm in migrating now. Refs: #2 --- Classes/Hooks/PageRendererPreProcess.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Classes/Hooks/PageRendererPreProcess.php b/Classes/Hooks/PageRendererPreProcess.php index 02cf04d..8065b11 100644 --- a/Classes/Hooks/PageRendererPreProcess.php +++ b/Classes/Hooks/PageRendererPreProcess.php @@ -4,6 +4,7 @@ namespace MMK2410\PlausibleAnalytics\Hooks; use TYPO3\CMS\Core\Page\AssetCollector; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Core\Context\Context; class PageRendererPreProcess { @@ -13,22 +14,30 @@ class PageRendererPreProcess /** @var \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController */ private $tsfe; + /** @var Context */ + private $context; + public function __construct(AssetCollector $assetCollector = null) { $this->assetCollector = $assetCollector ?? GeneralUtility::makeInstance(AssetCollector::class); $this->tsfe = $GLOBALS['TSFE'] ?? null; + $this->context = GeneralUtility::makeInstance(Context::class); } public function addLibrary(): void { - if (!isset($this->tsfe)) { + if (!isset($this->tsfe)|| !isset($this->context)) { return; } $domain = $this->getDomain(); $plausible = $this->getPlausibleURL(); - if (isset($domain) && isset($plausible) && !$this->tsfe->isBackendUserLoggedIn()) { + if ( + isset($domain) && + isset($plausible) && + !$this->context->getPropertyFromAspect('backend.user', 'isLoggedIn') + ) { $this->assetCollector->addJavaScript( 'plausible_analytics', $plausible . '/js/plausible.js',