Compare commits

...

4 Commits

Author SHA1 Message Date
Marcel Kapfer 09f9578d20
♻️ Use already existing asset collector
For some reason the AssetCollector instance created (or passed) in the
PageRendererPreProcess constructor was not used, but instead a new
instance was made as part of the addLibrary function.

This commit refactors PageRendererPreProcess::addLibrary to use the
already created AssetCollector.
2022-08-10 18:48:26 +02:00
Marcel Kapfer 9c43bfc8f5
🐛 Fix runtime crash if $GLOBALS: TSFE is not set on PHP 8 and higher
This is the case for the backend.

Setting it to null yields to an early abortion in the addLibrary
function.
2022-08-10 18:46:22 +02:00
Marcel Kapfer 01c8997c1d
⚰️ Remove unused use statement in PageRendererPreProcess 2022-08-10 18:45:33 +02:00
Marcel Kapfer 25ccc28ecc
⬆️ Raise dependencies to include TYPO3 v11 and PHP 8.0 & 8.1 2022-08-10 18:44:00 +02:00
3 changed files with 14 additions and 16 deletions

View File

@ -4,7 +4,6 @@ namespace MMK2410\PlausibleAnalytics\Hooks;
use TYPO3\CMS\Core\Page\AssetCollector;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
class PageRendererPreProcess
{
@ -17,7 +16,7 @@ class PageRendererPreProcess
public function __construct(AssetCollector $assetCollector = null)
{
$this->assetCollector = $assetCollector ?? GeneralUtility::makeInstance(AssetCollector::class);
$this->tsfe = $GLOBALS['TSFE'];
$this->tsfe = $GLOBALS['TSFE'] ?? null;
}
public function addLibrary(): void
@ -30,16 +29,15 @@ class PageRendererPreProcess
$plausible = $this->getPlausibleURL();
if (isset($domain) && isset($plausible) && !$this->tsfe->isBackendUserLoggedIn()) {
GeneralUtility::makeInstance(AssetCollector::class)
->addJavaScript(
'plausible_analytics',
$plausible . '/js/plausible.js',
[
'async' => 'async',
'defer' => 'defer',
'data-domain' => $domain
],
);
$this->assetCollector->addJavaScript(
'plausible_analytics',
$plausible . '/js/plausible.js',
[
'async' => 'async',
'defer' => 'defer',
'data-domain' => $domain
],
);
}
}

View File

@ -22,8 +22,8 @@
}
},
"require": {
"php": "7.2.0 - 7.4.99",
"typo3/cms-core": "^10.4"
"php": "7.2.0 - 8.1.99",
"typo3/cms-core": "^10.4 || ^11.5"
},
"replace": {
"typo3-ter/plausible-analytics": "self.version"

View File

@ -11,8 +11,8 @@ $EM_CONF[$_EXTKEY] = [
'version' => '1.1.0',
'constraints' => [
'depends' => [
'typo3' => '10.4.0-10.4.99',
'php' => '7.2.0-7.4.99'
'typo3' => '10.4.0-11.5.99',
'php' => '7.2.0-8.1.99'
],
],
'autoload' => [