[BUGFIX] additionalParameters for TCEMAIN.preview must handle arrays 11/43911/3
authorMarkus Klein <markus.klein@typo3.org>
Thu, 8 Oct 2015 16:06:49 +0000 (18:06 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 8 Oct 2015 18:50:56 +0000 (20:50 +0200)
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>
typo3/sysext/backend/Classes/Controller/EditDocumentController.php
typo3/sysext/backend/Tests/Unit/Controller/EditDocumentControllerTest.php [new file with mode: 0644]
typo3/sysext/core/Documentation/Changelog/7.2/Feature-66370-AddFlexiblePreviewUrlConfiguration.rst

index 911b6ac..15adce1 100644 (file)
@@ -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;
@@ -835,6 +837,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
         *
         * @return void
diff --git a/typo3/sysext/backend/Tests/Unit/Controller/EditDocumentControllerTest.php b/typo3/sysext/backend/Tests/Unit/Controller/EditDocumentControllerTest.php
new file mode 100644 (file)
index 0000000..1db0bca
--- /dev/null
@@ -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);
+       }
+
+}
index b224c3a..2e3d672 100644 (file)
@@ -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]
                        }
                }
        }