diff --git a/Classes/Controller/BackendController.php b/Classes/Controller/BackendController.php index 066c6ce..22c3c2c 100755 --- a/Classes/Controller/BackendController.php +++ b/Classes/Controller/BackendController.php @@ -2,10 +2,13 @@ namespace Websedit\WeCookieConsent\Controller; -use TYPO3\CMS\Backend\Attribute\Controller; +use Psr\Http\Message\ResponseInterface; use TYPO3\CMS\Backend\Template\ModuleTemplateFactory; -use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; +use TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface; +use TYPO3\CMS\Extbase\Persistence\QueryResultInterface; +use Websedit\WeCookieConsent\Domain\Repository\ServiceRepository; /*** * @@ -19,44 +22,31 @@ ***/ /** - * ServiceController + * BackendController */ -class BackendController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController +class BackendController extends ActionController { /** - * serviceRepository - * - * @var \Websedit\WeCookieConsent\Domain\Repository\ServiceRepository - */ - protected $serviceRepository = null; - - /** - * Inject a service repository + * Initializes the controller * * @param \Websedit\WeCookieConsent\Domain\Repository\ServiceRepository $serviceRepository */ - public function injectServiceRepository(\Websedit\WeCookieConsent\Domain\Repository\ServiceRepository $serviceRepository) + public function __construct(protected ServiceRepository $serviceRepository) { - $this->serviceRepository = $serviceRepository; } - // Prepared for TYPO3 12 compatibility - #public function __construct(protected readonly ModuleTemplateFactory $moduleTemplateFactory){} - /** * Action initializer * * @return void */ - protected function initializeAction() + protected function initializeAction(): void { - // @extensionScannerIgnoreLine - $pageId = (int)\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id'); - // Use this, when support for V10 is dropped - # $pageUid = (int)($this->request->getQueryParams()['id'] ?? $this->request->getParsedBody()['id'] ?? 0); - $frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK); - $persistenceConfiguration = array('persistence' => array('storagePid' => $pageId)); - $this->configurationManager->setConfiguration(array_merge($frameworkConfiguration, $persistenceConfiguration)); + $pageId = (int)($this->request->getQueryParams()['id'] ?? $this->request->getParsedBody()['id'] ?? 0); + + $querySettings = GeneralUtility::makeInstance(QuerySettingsInterface::class); + $querySettings->setStoragePageIds([$pageId]); + $this->serviceRepository->setDefaultQuerySettings($querySettings); } /** @@ -64,23 +54,21 @@ protected function initializeAction() * * @return \Psr\Http\Message\ResponseInterface */ - public function gtmWizardAction() + public function gtmWizardAction(): ResponseInterface { - $services = $this->serviceRepository->findByProvider('google-tagmanager-service'); + $services = $this->serviceRepository->findBy(['provider' => 'google-tagmanager-service']); $blocks = ['tags' => 1, 'triggers' => 1, 'variables' => 1]; - $this->view->assignMultiple([ + $moduleTemplateFactory = GeneralUtility::makeInstance(ModuleTemplateFactory::class); + $moduleTemplate = $moduleTemplateFactory->create($this->request); + + $moduleTemplate->assignMultiple([ 'services' => $services, 'gtmArray' => $this->createGtmArray($services, $blocks) ]); - if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() > 10) { - $moduleTemplateFactory = GeneralUtility::makeInstance(ModuleTemplateFactory::class); - $moduleTemplate = $moduleTemplateFactory->create($this->request); - $moduleTemplate->setContent($this->view->render()); - return $this->htmlResponse($moduleTemplate->renderContent()); - } + return $moduleTemplate->renderResponse(); } /** @@ -90,26 +78,15 @@ public function gtmWizardAction() * * @return \Psr\Http\Message\ResponseInterface */ - public function jsonDownloadAction($blocks) + public function jsonDownloadAction(array $blocks): ResponseInterface { - if ($this->response) { - $this->response->setHeader('Content-type', 'application/json'); - $this->response->setHeader('Content-Disposition', 'attachment; filename=import-this-to-gtm.json'); - } else { - //$this->response is empty in TYPO3 11.1. Maybe a change? Can't find further infos about it at the moment. - header('Content-type: application/json'); - header('Content-Disposition: attachment; filename=import-this-to-gtm.json'); - } - $services = $this->serviceRepository->findByProvider('google-tagmanager-service'); - $this->view->assignMultiple([ - 'gtmArray' => $this->createGtmArray($services, $blocks) - ]); + $json = json_encode($this->createGtmArray($services, $blocks), JSON_HEX_TAG); - // Backwards compatibility for TYPO3 V10 - if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() > 10) { - return $this->htmlResponse(); - } + return $this->jsonResponse($json) + ->withHeader('Content-type', 'application/json') + ->withHeader('Content-Disposition', 'attachment; filename=import-this-to-gtm.json') + ; } /** @@ -119,7 +96,7 @@ public function jsonDownloadAction($blocks) * @param array $blocks * @return array */ - private function createGtmArray($services, $blocks) + private function createGtmArray(QueryResultInterface $services, array $blocks): array { $gtmArray = [ "exportFormatVersion" => 2, diff --git a/Classes/ViewHelpers/Format/JsonViewHelper.php b/Classes/ViewHelpers/Format/JsonViewHelper.php index c2dbd97..9527281 100755 --- a/Classes/ViewHelpers/Format/JsonViewHelper.php +++ b/Classes/ViewHelpers/Format/JsonViewHelper.php @@ -19,6 +19,7 @@ public function initializeArguments() { $this->registerArgument('value', 'mixed', 'The incoming data to convert, or null if VH children should be used'); $this->registerArgument('forceObject', 'bool', 'Outputs an JSON object rather than an array', false, false); + $this->registerArgument('pretty', 'bool', 'Pretty print', false, false); } public function render() { @@ -27,6 +28,9 @@ public function render() { if ($this->arguments['forceObject'] !== false) { $options = $options | JSON_FORCE_OBJECT; } + if ($this->arguments['pretty'] !== false) { + $options = $options | JSON_PRETTY_PRINT; + } return json_encode($value, $options); } } \ No newline at end of file diff --git a/Resources/Private/Backend/Layouts-T3V10/Default.html b/Resources/Private/Backend/Layouts-T3V10/Default.html deleted file mode 100755 index 186d3de..0000000 --- a/Resources/Private/Backend/Layouts-T3V10/Default.html +++ /dev/null @@ -1,35 +0,0 @@ - - -
-
-
-
- - - - -
-
- - -
-
-
-
- -
-
- -
-
- -
-
-
- - -
-
-
-
- \ No newline at end of file diff --git a/Resources/Private/Backend/Layouts/Default.html b/Resources/Private/Backend/Layouts/Default.html deleted file mode 100755 index 530f792..0000000 --- a/Resources/Private/Backend/Layouts/Default.html +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/Resources/Private/Backend/Templates/Backend/JsonDownload.html b/Resources/Private/Backend/Templates/Backend/JsonDownload.html deleted file mode 100755 index 5293c3d..0000000 --- a/Resources/Private/Backend/Templates/Backend/JsonDownload.html +++ /dev/null @@ -1,3 +0,0 @@ - -{gtmArray} - \ No newline at end of file diff --git a/Resources/Private/Backend/Partials/Service/Table.html b/Resources/Private/Partials/Backend/Table.html similarity index 100% rename from Resources/Private/Backend/Partials/Service/Table.html rename to Resources/Private/Partials/Backend/Table.html diff --git a/Resources/Private/Backend/Templates/Backend/GtmWizard.html b/Resources/Private/Templates/Backend/GtmWizard.html similarity index 92% rename from Resources/Private/Backend/Templates/Backend/GtmWizard.html rename to Resources/Private/Templates/Backend/GtmWizard.html index 98d5299..ba7e5dd 100755 --- a/Resources/Private/Backend/Templates/Backend/GtmWizard.html +++ b/Resources/Private/Templates/Backend/GtmWizard.html @@ -1,5 +1,5 @@ - +

Google Tag Manager Export Wizard

@@ -17,17 +17,19 @@

Google Tag Manager Export Wizard

- + -
{gtmArray}
- -

Download JSON File

+ +
+
+ +
{gtmArray}
diff --git a/composer.json b/composer.json index 849eab7..e4b97a6 100755 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ ], "license": "GPL-2.0-or-later", "require": { - "typo3/cms-core": "^10.4 || ^11.1 || ^12.4" + "typo3/cms-core": "^10.4 || ^11.1 || ^12.4 || ^13.0" }, "autoload": { "psr-4": { @@ -36,6 +36,9 @@ "typo3-ter/we-cookie-consent": "self.version" }, "extra": { + "branch-alias": { + "dev-issue_38": "5.0.x-dev" + }, "typo3/cms": { "extension-key": "we_cookie_consent" } diff --git a/ext_emconf.php b/ext_emconf.php index bdb0396..09193c5 100755 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -21,12 +21,12 @@ 'uploadfolder' => false, 'clearcacheonload' => false, 'clearCacheOnLoad' => 0, - 'version' => '4.0.0', - 'constraints' => + 'version' => '5.0.0', + 'constraints' => array ( 'depends' => array ( - 'typo3' => '10.4.0-12.4.99', + 'typo3' => '13.0.0-13.4.99', ), 'conflicts' => array (