[BUGFIX] Add correct conversion of RTE pageTS config 11/54511/8
authorFrans Saris <franssaris@gmail.com>
Tue, 31 Oct 2017 15:32:51 +0000 (16:32 +0100)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Thu, 16 Nov 2017 14:23:56 +0000 (15:23 +0100)
Add all pageTS.RTE options to config without dots appended to the key
to be able to override the RTE config with pageTS like before.

Resolves: #82865
Releases: master, 8,7
Change-Id: Idb7d7d3b39d44ec37be8f93cc9de8b42b9c8a55c
Reviewed-on: https://review.typo3.org/54511
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Tested-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
typo3/sysext/core/Classes/Configuration/Richtext.php
typo3/sysext/core/Tests/Unit/Configuration/RichtextTest.php

index 93ac17b..3d39af9 100644 (file)
@@ -66,7 +66,7 @@ class Richtext
         // overlay preset configuration with pageTs
         ArrayUtility::mergeRecursiveWithOverrule(
             $configuration,
-            $this->cleanDotsFromEditorConfigKeys($pageTs)
+            $this->addFlattenedPageTsConfig($pageTs)
         );
 
         // Handle "mode" / "transformation" config when overridden
@@ -144,18 +144,22 @@ class Richtext
     }
 
     /**
-     * Strip dots from the 'editor.' part of a given TypoScript array
+     * Add all PageTS.RTE options keys to configuration without dots
      *
-     * @param array $typoScriptArray TypoScriptArray (with dots) that may contain an 'editor.' subarray
-     * @return array array with dots stripped from the editor subarray
+     * We need to keep the dotted keys for backwards compatibility like ext:rtehtmlarea
+     *
+     * @param array $typoScriptArray TypoScriptArray
+     * @return array array with config without dots added
      */
-    protected function cleanDotsFromEditorConfigKeys(array $typoScriptArray): array
+    protected function addFlattenedPageTsConfig(array $typoScriptArray): array
     {
-        if (isset($typoScriptArray['editor.'])) {
+        foreach ($typoScriptArray as $key => $data) {
+            if (substr($key, -1) !== '.') {
+                continue;
+            }
             /** @var TypoScriptService $typoScriptService */
             $typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
-            $typoScriptArray['editor'] = $typoScriptService->convertTypoScriptArrayToPlainArray($typoScriptArray['editor.']);
-            unset($typoScriptArray['editor.']);
+            $typoScriptArray[substr($key, 0, -1)] = $typoScriptService->convertTypoScriptArrayToPlainArray($typoScriptArray[$key]);
         }
 
         return $typoScriptArray;
index d4ba9c0..b9ee5b0 100644 (file)
@@ -34,7 +34,7 @@ class RichtextTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
         $pageTsConfig = [
             'properties' => [
                 'classes.' => [
-                    'aClass.' => 'aConfig',
+                    'aClass' => 'aConfig',
                 ],
                 'default.' => [
                     'removeComments' => '1',
@@ -56,12 +56,18 @@ class RichtextTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
         ];
         $expected = [
             'classes.' => [
-                'aClass.' => 'aConfig',
+                'aClass' => 'aConfig',
             ],
             'removeComments' => '1',
             'proc.' => [
                 'overruleMode' => 'myTransformation',
             ],
+            'classes' => [
+                'aClass' => 'aConfig',
+            ],
+            'proc' => [
+                'overruleMode' => 'myTransformation',
+            ],
         ];
         // Accessible mock to $subject since getRtePageTsConfigOfPid calls BackendUtility::getPagesTSconfig()
         // which can't be mocked in a sane way
@@ -83,7 +89,7 @@ class RichtextTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
         $pageTsConfig = [
             'properties' => [
                 'classes.' => [
-                    'aClass.' => 'aConfig',
+                    'aClass' => 'aConfig',
                 ],
                 'default.' => [
                     'removeComments' => '1',
@@ -101,12 +107,18 @@ class RichtextTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
         ];
         $expected = [
             'classes.' => [
-                'aClass.' => 'aConfig',
+                'aClass' => 'aConfig',
             ],
             'removeComments' => '1',
             'proc.' => [
                 'overruleMode' => 'myTransformation',
             ],
+            'classes' => [
+                'aClass' => 'aConfig',
+            ],
+            'proc' => [
+                'overruleMode' => 'myTransformation',
+            ],
         ];
         // Accessible mock to $subject since getRtePageTsConfigOfPid calls BackendUtility::getPagesTSconfig()
         // which can't be mocked in a sane way
@@ -128,7 +140,7 @@ class RichtextTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
         $pageTsConfig = [
             'properties' => [
                 'classes.' => [
-                    'aClass.' => 'aConfig',
+                    'aClass' => 'aConfig',
                 ],
                 'default.' => [
                     'removeComments' => '1',
@@ -137,9 +149,12 @@ class RichtextTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
         ];
         $expected = [
             'classes.' => [
-                'aClass.' => 'aConfig',
+                'aClass' => 'aConfig',
             ],
             'removeComments' => '1',
+            'classes' => [
+                'aClass' => 'aConfig',
+            ],
             'proc.' => [
                 'overruleMode' => 'default',
             ],
@@ -164,11 +179,11 @@ class RichtextTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
         $pageTsConfig = [
             'properties' => [
                 'classes.' => [
-                    'aClass.' => 'aConfig',
+                    'aClass' => 'aConfig',
                 ],
                 'default.' => [
                     'classes.' => [
-                        'aClass.' => 'anotherConfig',
+                        'aClass' => 'anotherConfig',
                     ],
                     'editor.' => [
                         'config.' => [
@@ -180,7 +195,15 @@ class RichtextTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
         ];
         $expected = [
             'classes.' => [
-                'aClass.' => 'anotherConfig',
+                'aClass' => 'anotherConfig',
+            ],
+            'editor.' => [
+                'config.' => [
+                    'contentsCss' => 'my.css'
+                ]
+            ],
+            'classes' => [
+                'aClass' => 'anotherConfig',
             ],
             'editor' => [
                 'config' => [
@@ -211,18 +234,18 @@ class RichtextTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
         $pageTsConfig = [
             'properties' => [
                 'classes.' => [
-                    'aClass.' => 'aConfig',
+                    'aClass' => 'aConfig',
                 ],
                 'default.' => [
                     'classes.' => [
-                        'aClass.' => 'anotherConfig',
+                        'aClass' => 'anotherConfig',
                     ],
                 ],
                 'config.' => [
                     'aTable.' => [
                         'aField.' => [
                             'classes.' => [
-                                'aClass.' => 'aThirdConfig',
+                                'aClass' => 'aThirdConfig',
                             ],
                             'editor.' => [
                                 'config.' => [
@@ -235,10 +258,19 @@ class RichtextTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
             ],
         ];
         $expected = [
+            // Config with pagets dots
             'classes.' => [
-                'aClass.' => 'aThirdConfig',
+                'aClass' => 'aThirdConfig',
+            ],
+            'editor.' => [
+                'config.' => [
+                    'contentsCss' => 'my.css'
+                ]
+            ],
+            // Config without pagets dots
+            'classes' => [
+                'aClass' => 'aThirdConfig',
             ],
-            // editor config without pagets dots
             'editor' => [
                 'config' => [
                     'contentsCss' => 'my.css'
@@ -268,18 +300,18 @@ class RichtextTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
         $pageTsConfig = [
             'properties' => [
                 'classes.' => [
-                    'aClass.' => 'aConfig',
+                    'aClass' => 'aConfig',
                 ],
                 'default.' => [
                     'classes.' => [
-                        'aClass.' => 'anotherConfig',
+                        'aClass' => 'anotherConfig',
                     ],
                 ],
                 'config.' => [
                     'aTable.' => [
                         'aField.' => [
                             'classes.' => [
-                                'aClass.' => 'aThirdConfig',
+                                'aClass' => 'aThirdConfig',
                             ],
                             'editor.' => [
                                 'config.' => [
@@ -289,7 +321,7 @@ class RichtextTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
                             'types.' => [
                                 'textmedia.' => [
                                     'classes.' => [
-                                        'aClass.' => 'aTypeSpecifcConfig',
+                                        'aClass' => 'aTypeSpecifcConfig',
                                     ],
                                     'editor.' => [
                                         'config.' => [
@@ -304,10 +336,19 @@ class RichtextTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
             ],
         ];
         $expected = [
+            // Config with pagets dots
             'classes.' => [
-                'aClass.' => 'aTypeSpecifcConfig',
+                'aClass' => 'aTypeSpecifcConfig',
+            ],
+            'editor.' => [
+                'config.' => [
+                    'contentsCss' => 'your.css'
+                ]
+            ],
+            // Config without pagets dots
+            'classes' => [
+                'aClass' => 'aTypeSpecifcConfig',
             ],
-            // editor config without pagets dots
             'editor' => [
                 'config' => [
                     'contentsCss' => 'your.css'
@@ -371,6 +412,11 @@ class RichtextTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
                 ],
             ],
             'preset' => 'default',
+            'editor.' => [
+                'config.' => [
+                    'width' => 200
+                ],
+            ],
             'proc.' => [
                 'overruleMode' => 'default',
             ],