Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 29 additions & 52 deletions Classes/Controller/BackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/***
*
Expand All @@ -19,68 +22,53 @@
***/

/**
* 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);
}

/**
* Preview the config
*
* @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();
}

/**
Expand All @@ -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')
;
}

/**
Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions Classes/ViewHelpers/Format/JsonViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);
}
}
35 changes: 0 additions & 35 deletions Resources/Private/Backend/Layouts-T3V10/Default.html

This file was deleted.

3 changes: 0 additions & 3 deletions Resources/Private/Backend/Layouts/Default.html

This file was deleted.

3 changes: 0 additions & 3 deletions Resources/Private/Backend/Templates/Backend/JsonDownload.html

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" xmlns:we="http://typo3.org/ns/Websedit/WeCookieConsent/ViewHelpers" data-namespace-typo3-fluid="true">
<f:layout name="Default"/>
<f:layout name="Module"/>
<f:section name="Content">
<h1>Google Tag Manager Export Wizard</h1>
<f:if condition="{services}">
Expand All @@ -17,17 +17,19 @@ <h1>Google Tag Manager Export Wizard</h1>
</thead>
<tbody>
<f:for each="{services}" as="service">
<f:render partial="Service/Table" arguments="{service:service}"/>
<f:render partial="Backend/Table" arguments="{service:service}"/>
</f:for>
</tbody>
</table>

<pre><we:format.json forceObject="true">{gtmArray}</we:format.json></pre>

<br/>
<h2>Download JSON File</h2>
<f:link.action action="jsonDownload" arguments="{blocks:'{tags:1, triggers:1, variables:1}'}" class="btn btn-success"><f:translate key="LLL:EXT:we_cookie_consent/Resources/Private/Language/locallang_mod1.xlf:download_json_all" /></f:link.action>
<f:link.action action="jsonDownload" arguments="{blocks:'{triggers:1, variables:1}'}" class="btn btn-success"><f:translate key="LLL:EXT:we_cookie_consent/Resources/Private/Language/locallang_mod1.xlf:download_json_triggerAndVariables" /></f:link.action>

<br/>
<br/>

<pre><we:format.json forceObject="true" pretty="true">{gtmArray}</we:format.json></pre>
</f:then>
<f:else>
<f:translate key="LLL:EXT:we_cookie_consent/Resources/Private/Language/locallang_mod1.xlf:no_google_tag_manager_services" />
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
}
Expand Down
6 changes: 3 additions & 3 deletions ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down