From d18e495b28d5c808cd6d13dad78613b08da7f2ef Mon Sep 17 00:00:00 2001
From: Tymoteusz Motylewski <t.motylewski@gmail.com>
Date: Wed, 30 May 2018 00:40:49 +0200
Subject: [PATCH] [BUGFIX] Correctly resolve RTE preset configuration for link
 browser

Replaces hardcoded RTE configuration in BrowseLinksController
with one resolved by Formengine when rendering a field.
This takes into account e.g. column overrides.

The RTE configuration preset name is now kept by Formengine in
['processedTca']['columns'][$fieldName]['config']['richtextConfigurationName']

Then it's being passed as parameter P[richtextConfigurationName] from RTE field
to the BrowseinksController

Resolves: #84943
Releases: master, 8.7
Change-Id: Id4f1c350f6eb6dfad4d49ec759a23939bbc45eda
Reviewed-on: https://review.typo3.org/56881
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Jan Stockfisch <jan.stockfisch@googlemail.com>
Tested-by: Jan Stockfisch <jan.stockfisch@googlemail.com>
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Tested-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
---
 .../backend/Classes/Form/FormDataProvider/TcaText.php      | 2 ++
 .../Tests/Unit/Form/FormDataProvider/TcaTextTest.php       | 1 +
 .../Classes/Controller/BrowseLinksController.php           | 7 ++++++-
 .../rte_ckeditor/Classes/Form/Element/RichTextElement.php  | 1 +
 4 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/typo3/sysext/backend/Classes/Form/FormDataProvider/TcaText.php b/typo3/sysext/backend/Classes/Form/FormDataProvider/TcaText.php
index c2c95eb618b3..49a45e11fefc 100644
--- a/typo3/sysext/backend/Classes/Form/FormDataProvider/TcaText.php
+++ b/typo3/sysext/backend/Classes/Form/FormDataProvider/TcaText.php
@@ -48,6 +48,8 @@ class TcaText implements FormDataProviderInterface
                     (string)$result['recordTypeValue'],
                     $fieldConfig['config']
                 );
+                // remember RTE preset name
+                $result['processedTca']['columns'][$fieldName]['config']['richtextConfigurationName'] = $fieldConfig['config']['richtextConfiguration'] ?? '';
                 // Add final resolved configuration to TCA array
                 $result['processedTca']['columns'][$fieldName]['config']['richtextConfiguration'] = $richtextConfiguration;
 
diff --git a/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/TcaTextTest.php b/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/TcaTextTest.php
index 03f5cc1fed8e..b86c09e65047 100644
--- a/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/TcaTextTest.php
+++ b/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/TcaTextTest.php
@@ -61,6 +61,7 @@ class TcaTextTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
                         'config' => [
                             'type' => 'text',
                             'enableRichtext' => true,
+                            'richtextConfigurationName' => '',
                             'richtextConfiguration' => [
                                 'aConfig' => 'option',
                             ],
diff --git a/typo3/sysext/rte_ckeditor/Classes/Controller/BrowseLinksController.php b/typo3/sysext/rte_ckeditor/Classes/Controller/BrowseLinksController.php
index 41f4139e878c..2fa92648b9a9 100644
--- a/typo3/sysext/rte_ckeditor/Classes/Controller/BrowseLinksController.php
+++ b/typo3/sysext/rte_ckeditor/Classes/Controller/BrowseLinksController.php
@@ -125,6 +125,11 @@ class BrowseLinksController extends AbstractLinkBrowserController
 
         $this->contentLanguageService->init($this->contentsLanguage);
 
+        $tcaFieldConf = ['enableRichtext' => true];
+        if (!empty($queryParameters['P']['richtextConfigurationName'])) {
+            $tcaFieldConf['richtextConfiguration'] = $queryParameters['P']['richtextConfigurationName'];
+        }
+
         /** @var Richtext $richtextConfigurationProvider */
         $richtextConfigurationProvider = GeneralUtility::makeInstance(Richtext::class);
         $this->thisConfig = $richtextConfigurationProvider->getConfiguration(
@@ -132,7 +137,7 @@ class BrowseLinksController extends AbstractLinkBrowserController
             $this->parameters['fieldName'],
             (int)$this->parameters['pid'],
             $this->parameters['recordType'],
-            ['richtext' => true]
+            $tcaFieldConf
         );
         $this->buttonConfig = $this->thisConfig['buttons']['link'] ?? [];
     }
diff --git a/typo3/sysext/rte_ckeditor/Classes/Form/Element/RichTextElement.php b/typo3/sysext/rte_ckeditor/Classes/Form/Element/RichTextElement.php
index f594507b090a..0695b7735521 100644
--- a/typo3/sysext/rte_ckeditor/Classes/Form/Element/RichTextElement.php
+++ b/typo3/sysext/rte_ckeditor/Classes/Form/Element/RichTextElement.php
@@ -209,6 +209,7 @@ class RichTextElement extends AbstractFormElement
                 'fieldName'  => $this->data['fieldName'],
                 'recordType' => $this->data['recordTypeValue'],
                 'pid'        => $this->data['effectivePid'],
+                'richtextConfigurationName' => $this->data['parameterArray']['fieldConf']['config']['richtextConfigurationName']
             ]
         ];
 
-- 
GitLab