[BUGFIX] CKEditor: UI language should respect BE user language 47/51947/3
authorBenni Mack <benni@typo3.org>
Sat, 4 Mar 2017 06:49:16 +0000 (07:49 +0100)
committerGeorg Ringer <georg.ringer@gmail.com>
Sat, 4 Mar 2017 19:17:52 +0000 (20:17 +0100)
If a backend user has selected a backend language,
CKEditor is not respecting this option, instead calculating
this based on the current browsers' language.

By default, CKeditor checks if the config option "language"
is set and if this is a valid language key, and translation is available
if not, it checks for the browser settings, if nothing matching found
it falls back to to the config option "defaultLanguage".

"defaultLanguage" should be set to "en", as the TYPO3 Backend
does as well.

The config option "language" should be calculated based on the
Backend Users' settings.

Resolves: #80133
Releases: master
Change-Id: I0f095ab7147871c2a4e8c8ea379754749bc1ba98
Reviewed-on: https://review.typo3.org/51947
Reviewed-by: Helmut Hummel <typo3@helhum.io>
Tested-by: Helmut Hummel <typo3@helhum.io>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Josef Glatz <josef.glatz@typo3.org>
Tested-by: Josef Glatz <josef.glatz@typo3.org>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/rte_ckeditor/Classes/Form/Element/RichTextElement.php
typo3/sysext/rte_ckeditor/Configuration/RTE/Editor/Base.yaml

index 52650ed..6677279 100644 (file)
@@ -17,6 +17,7 @@ namespace TYPO3\CMS\RteCKEditor\Form\Element;
 
 use TYPO3\CMS\Backend\Form\Element\AbstractFormElement;
 use TYPO3\CMS\Backend\Routing\UriBuilder;
+use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
 use TYPO3\CMS\Core\Localization\Locales;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\PathUtility;
@@ -255,7 +256,7 @@ class RichTextElement extends AbstractFormElement
     protected function prepareConfigurationForEditor(): array
     {
         // Ensure custom config is empty so nothing additional is loaded
-        // Of course this can be overriden by the editor configuration below
+        // Of course this can be overridden by the editor configuration below
         $configuration = [
             'customConfig' => '',
         ];
@@ -263,6 +264,10 @@ class RichTextElement extends AbstractFormElement
         if (is_array($this->rteConfiguration['config'])) {
             $configuration = array_replace_recursive($configuration, $this->rteConfiguration['config']);
         }
+        // Set the UI language of the editor if not hard-coded by the existing configuration
+        if (empty($configuration['language'])) {
+            $configuration['language'] = $this->getBackendUser()->uc['lang'] ?: ($this->getBackendUser()->user['lang'] ?: 'en');
+        }
         $configuration['contentsLanguage'] = $this->getLanguageIsoCodeOfContent();
 
         // replace all paths
@@ -291,4 +296,12 @@ class RichTextElement extends AbstractFormElement
         $fieldId = preg_replace('/[^a-zA-Z0-9_:.-]/', '_', $itemFormElementName);
         return htmlspecialchars(preg_replace('/^[^a-zA-Z]/', 'x', $fieldId));
     }
+
+    /**
+     * @return BackendUserAuthentication
+     */
+    protected function getBackendUser()
+    {
+        return $GLOBALS['BE_USER'];
+    }
 }
index cdeda10..0add8a3 100644 (file)
@@ -6,6 +6,7 @@ editor:
     contentsCss: "EXT:rte_ckeditor/Resources/Public/Css/contents.css"
     # will be overridden by the record (if a language is set)
     defaultContentLanguage: "en"
+    defaultLanguage: "en"
     height: 300
     width: "auto"
     toolbar: "Basic"