From 18dd60f9c6a2dc4007c8aff922073019c8540d0a Mon Sep 17 00:00:00 2001 From: Markus Klein <markus.klein@typo3.org> Date: Thu, 8 Oct 2015 18:06:49 +0200 Subject: [PATCH] [BUGFIX] additionalParameters for TCEMAIN.preview must handle arrays Resolves: #70294 Releases: master Change-Id: Iaa96e5132f473a91e5ed3352cf3f6820a07fa8b3 Reviewed-on: http://review.typo3.org/43911 Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl> Tested-by: Wouter Wolters <typo3@wouterwolters.nl> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> --- .../Controller/EditDocumentController.php | 25 +++++++++- .../Controller/EditDocumentControllerTest.php | 49 +++++++++++++++++++ ...370-AddFlexiblePreviewUrlConfiguration.rst | 2 +- 3 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 typo3/sysext/backend/Tests/Unit/Controller/EditDocumentControllerTest.php diff --git a/typo3/sysext/backend/Classes/Controller/EditDocumentController.php b/typo3/sysext/backend/Classes/Controller/EditDocumentController.php index 911b6ac11549..15adce19d2de 100644 --- a/typo3/sysext/backend/Classes/Controller/EditDocumentController.php +++ b/typo3/sysext/backend/Classes/Controller/EditDocumentController.php @@ -815,7 +815,9 @@ class EditDocumentController { // add/override parameters by configuration if (isset($previewConfiguration['additionalGetParameters.'])) { - $linkParameters = array_replace($linkParameters, $previewConfiguration['additionalGetParameters.']); + $additionalGetParameters = []; + $this->parseAdditionalGetParameters($additionalGetParameters, $previewConfiguration['additionalGetParameters.']); + $linkParameters = array_replace($linkParameters, $additionalGetParameters); } $this->popViewId = $previewPageId; @@ -834,6 +836,27 @@ class EditDocumentController { }'; } + /** + * Migrates a set of (possibly nested) GET parameters in TypoScript syntax to a plain array + * + * This basically removes the trailing dots of sub-array keys in TypoScript. + * The result can be used to create a query string with GeneralUtility::implodeArrayForUrl(). + * + * @param array $parameters Should be an empty array by default + * @param array $typoScript The TypoScript configuration + */ + protected function parseAdditionalGetParameters(array &$parameters, array $typoScript) { + foreach ($typoScript as $key => $value) { + if (is_array($value)) { + $key = rtrim($key, '.'); + $parameters[$key] = []; + $this->parseAdditionalGetParameters($parameters[$key], $value); + } else { + $parameters[$key] = $value; + } + } + } + /** * Main module operation * diff --git a/typo3/sysext/backend/Tests/Unit/Controller/EditDocumentControllerTest.php b/typo3/sysext/backend/Tests/Unit/Controller/EditDocumentControllerTest.php new file mode 100644 index 000000000000..1db0bca93d8b --- /dev/null +++ b/typo3/sysext/backend/Tests/Unit/Controller/EditDocumentControllerTest.php @@ -0,0 +1,49 @@ +<?php +namespace TYPO3\CMS\Backend\Tests\Unit\Controller; + +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ + +use TYPO3\CMS\Backend\Controller\EditDocumentController; +use TYPO3\CMS\Core\Tests\UnitTestCase; + +/** + * Tests for EditDocumentController + */ +class EditDocumentControllerTest extends UnitTestCase { + + /** + * @test + */ + public function parseAdditionalGetParametersCreatesCorrectParameterArray() { + $typoScript = [ + 'tx_myext.' => [ + 'controller' => 'test', + 'action' => 'run' + ], + 'magic' => 'yes' + ]; + $expectedParameters = [ + 'tx_myext' => [ + 'controller' => 'test', + 'action' => 'run' + ], + 'magic' => 'yes' + ]; + $result = []; + $mock = $this->getAccessibleMock(EditDocumentController::class, ['dummy'], [], '', FALSE); + $mock->_callRef('parseAdditionalGetParameters', $result, $typoScript); + $this->assertSame($expectedParameters, $result); + } + +} diff --git a/typo3/sysext/core/Documentation/Changelog/7.2/Feature-66370-AddFlexiblePreviewUrlConfiguration.rst b/typo3/sysext/core/Documentation/Changelog/7.2/Feature-66370-AddFlexiblePreviewUrlConfiguration.rst index b224c3a97ff0..2e3d672fb640 100644 --- a/typo3/sysext/core/Documentation/Changelog/7.2/Feature-66370-AddFlexiblePreviewUrlConfiguration.rst +++ b/typo3/sysext/core/Documentation/Changelog/7.2/Feature-66370-AddFlexiblePreviewUrlConfiguration.rst @@ -29,7 +29,7 @@ New page TSconfig is introduced. The options are: uid = tx_myext_pi1[showUid] } additionalGetParameters { - tx_myext_pi1[special] = HELLO + tx_myext_pi1.special = HELLO # results in tx_myext_pi1[special] } } } -- GitLab