[BUGFIX] Clearing label through TS doesn't work 95/20495/2
authorMarkus Klein <klein.t3@mfc-linz.at>
Fri, 5 Apr 2013 19:02:00 +0000 (21:02 +0200)
committerMarkus Klein <klein.t3@mfc-linz.at>
Tue, 7 May 2013 19:34:24 +0000 (21:34 +0200)
Overriding labels of non-default languages using TypoScript
fails if the value is empty.
The problem is that we cannot distinguish between missing translations
and labels cleared by TypoScript.
(In both cases ['target'] === "")

Change-Id: Iac666ecd7fa9af900f9852a777be3127437e0365
Fixes: #43959
Releases: 6.2, 6.1, 6.0, 4.7
Reviewed-on: https://review.typo3.org/20495
Reviewed-by: Markus Klein
Tested-by: Markus Klein
typo3/sysext/frontend/Classes/Plugin/AbstractPlugin.php

index 00e586b..97b46c7 100644 (file)
@@ -98,6 +98,16 @@ class AbstractPlugin {
         */
        public $LOCAL_LANG = array();
 
+       /**
+        * Contains those LL keys, which have been set to (empty) in TypoScript.
+        * This is necessary, as we cannot distinguish between a nonexisting
+        * translation and a label that has been cleared by TS.
+        * In both cases ['key'][0]['target'] is "".
+        *
+        * @var array
+        */
+       protected $LOCAL_LANG_UNSET = array();
+
        // Local Language content charset for individual labels (overriding)
        /**
         * @todo Define visibility
@@ -865,7 +875,9 @@ class AbstractPlugin {
         */
        public function pi_getLL($key, $alternativeLabel = '', $hsc = FALSE) {
                $word = NULL;
-               if (!empty($this->LOCAL_LANG[$this->LLkey][$key][0]['target'])) {
+               if (!empty($this->LOCAL_LANG[$this->LLkey][$key][0]['target'])
+                       || isset($this->LOCAL_LANG_UNSET[$this->LLkey][$key])
+               ) {
                        // The "from" charset of csConv() is only set for strings from TypoScript via _LOCAL_LANG
                        if (isset($this->LOCAL_LANG_charset[$this->LLkey][$key])) {
                                $word = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->LLkey][$key][0]['target'], $this->LOCAL_LANG_charset[$this->LLkey][$key]);
@@ -876,7 +888,9 @@ class AbstractPlugin {
                        $alternativeLanguageKeys = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->altLLkey, TRUE);
                        $alternativeLanguageKeys = array_reverse($alternativeLanguageKeys);
                        foreach ($alternativeLanguageKeys as $languageKey) {
-                               if (!empty($this->LOCAL_LANG[$languageKey][$key][0]['target'])) {
+                               if (!empty($this->LOCAL_LANG[$languageKey][$key][0]['target'])
+                                       || isset($this->LOCAL_LANG_UNSET[$languageKey][$key])
+                               ) {
                                        // Alternative language translation for key exists
                                        $word = $this->LOCAL_LANG[$languageKey][$key][0]['target'];
                                        // The "from" charset of csConv() is only set for strings from TypoScript via _LOCAL_LANG
@@ -891,7 +905,9 @@ class AbstractPlugin {
                        }
                }
                if ($word === NULL) {
-                       if (!empty($this->LOCAL_LANG['default'][$key][0]['target'])) {
+                       if (!empty($this->LOCAL_LANG['default'][$key][0]['target'])
+                               || isset($this->LOCAL_LANG_UNSET['default'][$key])
+                       ) {
                                // Get default translation (without charset conversion, english)
                                $word = $this->LOCAL_LANG['default'][$key][0]['target'];
                        } else {
@@ -928,16 +944,20 @@ class AbstractPlugin {
                                }
                        }
                        // Overlaying labels from TypoScript (including fictitious language keys for non-system languages!):
-                       $confLL = $this->conf['_LOCAL_LANG.'];
-                       if (is_array($confLL)) {
-                               foreach ($confLL as $languageKey => $languageArray) {
-                                       // Don't process label if the langue is not loaded
+                       if (isset($this->conf['_LOCAL_LANG.'])) {
+                               // Clear the "unset memory"
+                               $this->LOCAL_LANG_UNSET = array();
+                               foreach ($this->conf['_LOCAL_LANG.'] as $languageKey => $languageArray) {
+                                       // Remove the dot after the language key
                                        $languageKey = substr($languageKey, 0, -1);
-                                       if (is_array($languageArray) && is_array($this->LOCAL_LANG[$languageKey])) {
-                                               // Remove the dot after the language key
+                                       // Don't process label if the language is not loaded
+                                       if (is_array($languageArray) && isset($this->LOCAL_LANG[$languageKey])) {
                                                foreach ($languageArray as $labelKey => $labelValue) {
                                                        if (!is_array($labelValue)) {
                                                                $this->LOCAL_LANG[$languageKey][$labelKey][0]['target'] = $labelValue;
+                                                               if ($labelValue === '') {
+                                                                       $this->LOCAL_LANG_UNSET[$languageKey][$labelKey] = '';
+                                                               }
                                                                $this->LOCAL_LANG_charset[$languageKey][$labelKey] = 'utf-8';
                                                        }
                                                }