✨ Use Context API to check for logged in backend user
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
This commit is contained in:
parent
89ee94bf28
commit
8264969c61
1 changed files with 11 additions and 2 deletions
|
@ -4,6 +4,7 @@ namespace MMK2410\PlausibleAnalytics\Hooks;
|
||||||
|
|
||||||
use TYPO3\CMS\Core\Page\AssetCollector;
|
use TYPO3\CMS\Core\Page\AssetCollector;
|
||||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||||
|
use TYPO3\CMS\Core\Context\Context;
|
||||||
|
|
||||||
class PageRendererPreProcess
|
class PageRendererPreProcess
|
||||||
{
|
{
|
||||||
|
@ -13,22 +14,30 @@ class PageRendererPreProcess
|
||||||
/** @var \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController */
|
/** @var \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController */
|
||||||
private $tsfe;
|
private $tsfe;
|
||||||
|
|
||||||
|
/** @var Context */
|
||||||
|
private $context;
|
||||||
|
|
||||||
public function __construct(AssetCollector $assetCollector = null)
|
public function __construct(AssetCollector $assetCollector = null)
|
||||||
{
|
{
|
||||||
$this->assetCollector = $assetCollector ?? GeneralUtility::makeInstance(AssetCollector::class);
|
$this->assetCollector = $assetCollector ?? GeneralUtility::makeInstance(AssetCollector::class);
|
||||||
$this->tsfe = $GLOBALS['TSFE'] ?? null;
|
$this->tsfe = $GLOBALS['TSFE'] ?? null;
|
||||||
|
$this->context = GeneralUtility::makeInstance(Context::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addLibrary(): void
|
public function addLibrary(): void
|
||||||
{
|
{
|
||||||
if (!isset($this->tsfe)) {
|
if (!isset($this->tsfe)|| !isset($this->context)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$domain = $this->getDomain();
|
$domain = $this->getDomain();
|
||||||
$plausible = $this->getPlausibleURL();
|
$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(
|
$this->assetCollector->addJavaScript(
|
||||||
'plausible_analytics',
|
'plausible_analytics',
|
||||||
$plausible . '/js/plausible.js',
|
$plausible . '/js/plausible.js',
|
||||||
|
|
Loading…
Reference in a new issue