From 7e36c6eda89645d7de93df39740b9b14932d60b3 Mon Sep 17 00:00:00 2001
From: Frans Saris <franssaris@gmail.com>
Date: Sun, 19 Feb 2017 21:28:30 +0100
Subject: [PATCH] [BUGFIX] Refactor CKEditor to be inline with the
 AbstractLinkBrowser

The internals of the LinkBrowser and LinkHandler depend on all the
field specific info to be in the P parameter.

Further the DatabaseBrowser used by the RecordBrowser fetches the table
parameter form global url query scope what collides with the params set
by the CKEditor RichTextElement.

To prevent the parameter collision the params set by the RichTextElement
are moved to the P prefix what is also more inline with the other
LinkBrowser implementations.

This patch also resolves the lasts issues related to the new
recordHandler + CKEditor.

Resolves: #79645
Releases: master
Change-Id: Id7cab0f0a012c5de11a2038e1d579d87599d47cd
Reviewed-on: https://review.typo3.org/51760
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
---
 .../Controller/BrowseLinksController.php      | 40 ++++++-------------
 .../Classes/Form/Element/RichTextElement.php  | 12 +++---
 2 files changed, 20 insertions(+), 32 deletions(-)

diff --git a/typo3/sysext/rte_ckeditor/Classes/Controller/BrowseLinksController.php b/typo3/sysext/rte_ckeditor/Classes/Controller/BrowseLinksController.php
index e259fc19d1bf..8b411c1615f4 100644
--- a/typo3/sysext/rte_ckeditor/Classes/Controller/BrowseLinksController.php
+++ b/typo3/sysext/rte_ckeditor/Classes/Controller/BrowseLinksController.php
@@ -57,13 +57,6 @@ class BrowseLinksController extends AbstractLinkBrowserController
      */
     protected $thisConfig = [];
 
-    /**
-     * Used with the Rich Text Editor.
-     *
-     * @var array
-     */
-    protected $editorDetails = [];
-
     /**
      * @var array
      */
@@ -125,28 +118,20 @@ class BrowseLinksController extends AbstractLinkBrowserController
 
         $this->siteUrl = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
 
-        $currentLinkParts = isset($queryParameters['curUrl']) ? $queryParameters['curUrl'] : [];
-        $this->currentLinkParts = $currentLinkParts;
-        $this->editorId = GeneralUtility::_GP('editorId');
-        $this->contentsLanguage = GeneralUtility::_GP('contentsLanguage');
-        $this->RTEtsConfigParams = GeneralUtility::_GP('RTEtsConfigParams');
+        $this->currentLinkParts = $queryParameters['curUrl'] ?? [];
+        $this->editorId = $queryParameters['editorId'];
+        $this->contentsLanguage = $queryParameters['contentsLanguage'];
+        $this->RTEtsConfigParams = $queryParameters['RTEtsConfigParams'] ?? null;
 
         $this->contentLanguageService->init($this->contentsLanguage);
 
-        $this->editorDetails = [
-            'table' => $queryParameters['table'],
-            'uid' => $queryParameters['uid'],
-            'fieldName' => $queryParameters['fieldName'],
-            'pid' => $queryParameters['pid'],
-            'recordType' => $queryParameters['recordType'],
-        ];
-
+        /** @var Richtext $richtextConfigurationProvider */
         $richtextConfigurationProvider = GeneralUtility::makeInstance(Richtext::class);
         $this->thisConfig = $richtextConfigurationProvider->getConfiguration(
-            $queryParameters['table'],
-            $queryParameters['fieldName'],
-            (int)$queryParameters['pid'],
-            $queryParameters['recordType'],
+            $this->parameters['table'],
+            $this->parameters['fieldName'],
+            (int)$this->parameters['pid'],
+            $this->parameters['recordType'],
             ['richtext' => true]
         );
         $this->buttonConfig = $this->thisConfig['buttons.']['link.'] ?? [];
@@ -530,7 +515,7 @@ class BrowseLinksController extends AbstractLinkBrowserController
      */
     protected function getCurrentPageId()
     {
-        return (int)$this->editorDetails['pid'];
+        return (int)$this->parameters['pid'];
     }
 
     /**
@@ -565,10 +550,11 @@ class BrowseLinksController extends AbstractLinkBrowserController
      */
     public function getUrlParameters(array $overrides = null)
     {
-        return array_merge($this->editorDetails, [
+        return [
             'act' => isset($overrides['act']) ? $overrides['act'] : $this->displayedLinkHandlerId,
             'editorId' => $this->editorId,
             'contentsLanguage' => $this->contentsLanguage,
-        ]);
+            'P' => $this->parameters
+        ];
     }
 }
diff --git a/typo3/sysext/rte_ckeditor/Classes/Form/Element/RichTextElement.php b/typo3/sysext/rte_ckeditor/Classes/Form/Element/RichTextElement.php
index 89f134423b7f..4906b4ec21b9 100644
--- a/typo3/sysext/rte_ckeditor/Classes/Form/Element/RichTextElement.php
+++ b/typo3/sysext/rte_ckeditor/Classes/Form/Element/RichTextElement.php
@@ -196,11 +196,13 @@ class RichTextElement extends AbstractFormElement
     protected function getExtraPlugins(): array
     {
         $urlParameters = [
-            'table'      => $this->data['tableName'],
-            'uid'        => $this->data['databaseRow']['uid'],
-            'fieldName'  => $this->data['fieldName'],
-            'recordType' => $this->data['recordTypeValue'],
-            'pid'        => $this->data['effectivePid'],
+            'P' => [
+                'table'      => $this->data['tableName'],
+                'uid'        => $this->data['databaseRow']['uid'],
+                'fieldName'  => $this->data['fieldName'],
+                'recordType' => $this->data['recordTypeValue'],
+                'pid'        => $this->data['effectivePid'],
+            ]
         ];
 
         $pluginConfiguration = [];
-- 
GitLab