[BUGFIX] Allow to override RTE config via PageTS 51/53551/2
authorHannes Lau <office@hanneslau.de>
Sat, 15 Jul 2017 13:29:00 +0000 (15:29 +0200)
committerBenni Mack <benni@typo3.org>
Thu, 20 Jul 2017 09:11:52 +0000 (11:11 +0200)
Fix the merging of YAML and PageTS provided RTE configuration to allow
editor configuration via PageTS

Resolves: #81880
Releases: master, 8.7
Change-Id: Ic06627686b6ee77d79df34a6dda7b5610ccb06cb
Reviewed-on: https://review.typo3.org/53551
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/core/Classes/Configuration/Richtext.php
typo3/sysext/core/Tests/Unit/Configuration/RichtextTest.php

index 202906a..893d3fd 100644 (file)
@@ -18,6 +18,7 @@ namespace TYPO3\CMS\Core\Configuration;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
 use TYPO3\CMS\Core\Configuration\Loader\YamlFileLoader;
+use TYPO3\CMS\Core\TypoScript\TypoScriptService;
 use TYPO3\CMS\Core\Utility\ArrayUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
@@ -72,23 +73,32 @@ class Richtext
         unset($fullPageTsConfig['default.'], $fullPageTsConfig['config.']);
         // RTE.* (used for RTE.classesAnchor or similar in RTEHtmlArea)
         if (!empty($fullPageTsConfig)) {
-            ArrayUtility::mergeRecursiveWithOverrule($configuration, $fullPageTsConfig);
+            ArrayUtility::mergeRecursiveWithOverrule(
+                $configuration,
+                $this->cleanDotsFromEditorConfigKeys($fullPageTsConfig)
+            );
         }
         // RTE.default.*
         if (is_array($defaultPageTsConfigOverrides)) {
-            ArrayUtility::mergeRecursiveWithOverrule($configuration, $defaultPageTsConfigOverrides);
+            ArrayUtility::mergeRecursiveWithOverrule(
+                $configuration,
+                $this->cleanDotsFromEditorConfigKeys($defaultPageTsConfigOverrides)
+            );
         }
         // RTE.config.tt_content.bodytext and based on type as well
         if (is_array($fieldSpecificPageTsConfigOverrides)) {
             $fieldSpecificPageTsConfigOverridesWithoutType = $fieldSpecificPageTsConfigOverrides;
             unset($fieldSpecificPageTsConfigOverridesWithoutType['types.']);
-            ArrayUtility::mergeRecursiveWithOverrule($configuration, $fieldSpecificPageTsConfigOverridesWithoutType);
+            ArrayUtility::mergeRecursiveWithOverrule(
+                $configuration,
+                $this->cleanDotsFromEditorConfigKeys($fieldSpecificPageTsConfigOverridesWithoutType)
+            );
             if ($recordType
                 && isset($fieldSpecificPageTsConfigOverrides['types.'][$recordType . '.'])
                 && is_array($fieldSpecificPageTsConfigOverrides['types.'][$recordType . '.'])) {
                 ArrayUtility::mergeRecursiveWithOverrule(
                     $configuration,
-                    $fieldSpecificPageTsConfigOverrides['types.'][$recordType . '.']
+                    $this->cleanDotsFromEditorConfigKeys($fieldSpecificPageTsConfigOverrides['types.'][$recordType . '.'])
                 );
             }
         }
@@ -176,4 +186,22 @@ class Richtext
     {
         return $GLOBALS['BE_USER'];
     }
+
+    /**
+     * Strip dots from the 'editor.' part of a given TypoScript array
+     *
+     * @param array $typoScriptArray TypoScriptArray (with dots) that may contain an 'editor.' subarray
+     * @return array array with dots stripped from the editor subarray
+     */
+    protected function cleanDotsFromEditorConfigKeys(array $typoScriptArray): array
+    {
+        if (isset($typoScriptArray['editor.'])) {
+            /** @var TypoScriptService $typoScriptService */
+            $typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
+            $typoScriptArray['editor'] = $typoScriptService->convertTypoScriptArrayToPlainArray($typoScriptArray['editor.']);
+            unset($typoScriptArray['editor.']);
+        }
+
+        return $typoScriptArray;
+    }
 }
index d872a98..0da1d38 100644 (file)
@@ -207,6 +207,11 @@ class RichtextTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
                     'classes.' => [
                         'aClass.' => 'anotherConfig',
                     ],
+                    'editor.' => [
+                        'config.' => [
+                            'contentsCss' => 'my.css'
+                        ]
+                    ],
                 ],
             ],
         ];
@@ -214,6 +219,11 @@ class RichtextTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
             'classes.' => [
                 'aClass.' => 'anotherConfig',
             ],
+            'editor' => [
+                'config' => [
+                    'contentsCss' => 'my.css'
+                ]
+            ],
             'proc.' => [
                 'overruleMode' => 'default',
             ],
@@ -251,6 +261,11 @@ class RichtextTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
                             'classes.' => [
                                 'aClass.' => 'aThirdConfig',
                             ],
+                            'editor.' => [
+                                'config.' => [
+                                    'contentsCss' => 'my.css'
+                                ]
+                            ],
                         ],
                     ],
                 ],
@@ -260,6 +275,12 @@ class RichtextTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
             'classes.' => [
                 'aClass.' => 'aThirdConfig',
             ],
+            // editor config without pagets dots
+            'editor' => [
+                'config' => [
+                    'contentsCss' => 'my.css'
+                ]
+            ],
             'proc.' => [
                 'overruleMode' => 'default',
             ],
@@ -297,11 +318,21 @@ class RichtextTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
                             'classes.' => [
                                 'aClass.' => 'aThirdConfig',
                             ],
+                            'editor.' => [
+                                'config.' => [
+                                    'contentsCss' => 'my.css'
+                                ]
+                            ],
                             'types.' => [
                                 'textmedia.' => [
                                     'classes.' => [
                                         'aClass.' => 'aTypeSpecifcConfig',
                                     ],
+                                    'editor.' => [
+                                        'config.' => [
+                                            'contentsCss' => 'your.css'
+                                        ]
+                                    ],
                                 ]
                             ]
                         ],
@@ -313,6 +344,12 @@ class RichtextTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
             'classes.' => [
                 'aClass.' => 'aTypeSpecifcConfig',
             ],
+            // editor config without pagets dots
+            'editor' => [
+                'config' => [
+                    'contentsCss' => 'your.css'
+                ]
+            ],
             'proc.' => [
                 'overruleMode' => 'default',
             ],