[BUGFIX] Refactor CKEditor to be inline with the AbstractLinkBrowser
[Packages/TYPO3.CMS.git] / typo3 / sysext / rte_ckeditor / Classes / Controller / BrowseLinksController.php
index f6bbe76..8b411c1 100644 (file)
@@ -16,7 +16,7 @@ namespace TYPO3\CMS\RteCKEditor\Controller;
  */
 
 use Psr\Http\Message\ServerRequestInterface;
-use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Configuration\Richtext;
 use TYPO3\CMS\Core\LinkHandling\LinkService;
 use TYPO3\CMS\Core\Page\PageRenderer;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -38,7 +38,7 @@ class BrowseLinksController extends AbstractLinkBrowserController
      *
      * @var int
      */
-    protected $contentTypo3Language;
+    protected $contentsLanguage;
 
     /**
      * Language service object for localization to the content language
@@ -58,21 +58,6 @@ class BrowseLinksController extends AbstractLinkBrowserController
     protected $thisConfig = [];
 
     /**
-     * RTE configuration
-     *
-     * @var array
-     */
-    protected $RTEProperties = [];
-
-    /**
-     * Used with the Rich Text Editor.
-     * Example value: "tt_content:NEW3fba58c969f5c:bodytext:23:text:23:"
-     *
-     * @var string
-     */
-    protected $RTEtsConfigParams;
-
-    /**
      * @var array
      */
     protected $classesAnchorDefault = [];
@@ -133,19 +118,22 @@ 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->contentTypo3Language = GeneralUtility::_GP('contentTypo3Language');
-        $this->RTEtsConfigParams = GeneralUtility::_GP('RTEtsConfigParams');
-
-        $this->contentLanguageService->init($this->contentTypo3Language);
-
-        $RTEtsConfigParts = explode(':', $this->RTEtsConfigParams);
-        $RTEsetup = $this->getBackendUser()->getTSConfig('RTE', BackendUtility::getPagesTSconfig($RTEtsConfigParts[5]));
-        $this->RTEProperties = $RTEsetup['properties'];
-
-        $this->thisConfig = BackendUtility::RTEsetup($this->RTEProperties, $RTEtsConfigParts[0], $RTEtsConfigParts[2], $RTEtsConfigParts[4]);
+        $this->currentLinkParts = $queryParameters['curUrl'] ?? [];
+        $this->editorId = $queryParameters['editorId'];
+        $this->contentsLanguage = $queryParameters['contentsLanguage'];
+        $this->RTEtsConfigParams = $queryParameters['RTEtsConfigParams'] ?? null;
+
+        $this->contentLanguageService->init($this->contentsLanguage);
+
+        /** @var Richtext $richtextConfigurationProvider */
+        $richtextConfigurationProvider = GeneralUtility::makeInstance(Richtext::class);
+        $this->thisConfig = $richtextConfigurationProvider->getConfiguration(
+            $this->parameters['table'],
+            $this->parameters['fieldName'],
+            (int)$this->parameters['pid'],
+            $this->parameters['recordType'],
+            ['richtext' => true]
+        );
         $this->buttonConfig = $this->thisConfig['buttons.']['link.'] ?? [];
     }
 
@@ -213,8 +201,8 @@ class BrowseLinksController extends AbstractLinkBrowserController
             ];
             $titleReadOnly = $this->buttonConfig['properties.']['title.']['readOnly']
                 || $this->buttonConfig[$this->displayedLinkHandlerId . '.']['properties.']['title.']['readOnly'];
-            if (is_array($this->RTEProperties['classesAnchor.'])) {
-                foreach ($this->RTEProperties['classesAnchor.'] as $label => $conf) {
+            if (is_array($this->thisConfig['classesAnchor.'])) {
+                foreach ($this->thisConfig['classesAnchor.'] as $label => $conf) {
                     if (in_array($conf['class'], $classesAnchorArray, true)) {
                         $classesAnchor['all'][] = $conf['class'];
                         if ($conf['type'] === $this->displayedLinkHandlerId) {
@@ -248,11 +236,11 @@ class BrowseLinksController extends AbstractLinkBrowserController
                     if ($this->linkAttributeValues['class'] === $class || !$this->linkAttributeValues['class'] && $this->classesAnchorDefault[$this->displayedLinkHandlerId] == $class) {
                         $selected = 'selected="selected"';
                     }
-                    $classLabel = !empty($this->RTEProperties['classes.'][$class . '.']['name'])
-                        ? $this->getPageConfigLabel($this->RTEProperties['classes.'][$class . '.']['name'], 0)
+                    $classLabel = !empty($this->thisConfig['classes.'][$class . '.']['name'])
+                        ? $this->getPageConfigLabel($this->thisConfig['classes.'][$class . '.']['name'], 0)
                         : $class;
-                    $classStyle = !empty($this->RTEProperties['classes.'][$class . '.']['value'])
-                        ? $this->RTEProperties['classes.'][$class . '.']['value']
+                    $classStyle = !empty($this->thisConfig['classes.'][$class . '.']['value'])
+                        ? $this->thisConfig['classes.'][$class . '.']['value']
                         : '';
                     $this->classesAnchorJSOptions[$this->displayedLinkHandlerId] .= '<option ' . $selected . ' value="' . $class . '"' . ($classStyle ? ' style="' . $classStyle . '"' : '') . '>' . $classLabel . '</option>';
                 }
@@ -276,8 +264,8 @@ class BrowseLinksController extends AbstractLinkBrowserController
 
         // todo: find new name for this option
         // Initializing additional attributes
-        if ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rtehtmlarea']['plugins']['TYPO3Link']['additionalAttributes']) {
-            $addAttributes = GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rtehtmlarea']['plugins']['TYPO3Link']['additionalAttributes'], true);
+        if ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rte_ckeditor']['plugins']['TYPO3Link']['additionalAttributes']) {
+            $addAttributes = GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rte_ckeditor']['plugins']['TYPO3Link']['additionalAttributes'], true);
             foreach ($addAttributes as $attribute) {
                 $this->additionalAttributes[$attribute] = $this->linkAttributeValues[$attribute] ?? '';
             }
@@ -527,7 +515,7 @@ class BrowseLinksController extends AbstractLinkBrowserController
      */
     protected function getCurrentPageId()
     {
-        return explode(':', $this->RTEtsConfigParams)[5];
+        return (int)$this->parameters['pid'];
     }
 
     /**
@@ -565,8 +553,8 @@ class BrowseLinksController extends AbstractLinkBrowserController
         return [
             'act' => isset($overrides['act']) ? $overrides['act'] : $this->displayedLinkHandlerId,
             'editorId' => $this->editorId,
-            'contentTypo3Language' => $this->contentTypo3Language,
-            'RTEtsConfigParams' => $this->RTEtsConfigParams,
+            'contentsLanguage' => $this->contentsLanguage,
+            'P' => $this->parameters
         ];
     }
 }