Fix legacy i18n value handling in i18n form fields
authorMatthias Schmidt <gravatronics@live.com>
Sat, 4 Jan 2020 16:08:06 +0000 (17:08 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Sat, 4 Jan 2020 16:08:06 +0000 (17:08 +0100)
Close #3122

com.woltlab.wcf/templates/__textFormField.tpl
wcfsetup/install/files/acp/templates/__textFormField.tpl
wcfsetup/install/files/lib/system/form/builder/field/TI18nFormField.class.php

index 44a3cda275abe7e7705290d85e7b4477a65cae30..8d73e00153ae9a75fe0c81449d49e0acb371902f 100644 (file)
@@ -1,7 +1,7 @@
 <input type="text" {*
        *}id="{@$field->getPrefixedId()}" {*
        *}name="{@$field->getPrefixedId()}" {*
-       *}value="{if !$field->isI18n() || !$field->hasI18nValues()}{$field->getValue()}{/if}" {*
+       *}value="{if !$field->isI18n() || !$field->hasI18nValues() || $availableLanguages|count === 1}{$field->getValue()}{/if}" {*
        *}class="long"{*
        *}{if $field->isAutofocused()} autofocus{/if}{*
        *}{if $field->isRequired()} required{/if}{*
index 44a3cda275abe7e7705290d85e7b4477a65cae30..8d73e00153ae9a75fe0c81449d49e0acb371902f 100644 (file)
@@ -1,7 +1,7 @@
 <input type="text" {*
        *}id="{@$field->getPrefixedId()}" {*
        *}name="{@$field->getPrefixedId()}" {*
-       *}value="{if !$field->isI18n() || !$field->hasI18nValues()}{$field->getValue()}{/if}" {*
+       *}value="{if !$field->isI18n() || !$field->hasI18nValues() || $availableLanguages|count === 1}{$field->getValue()}{/if}" {*
        *}class="long"{*
        *}{if $field->isAutofocused()} autofocus{/if}{*
        *}{if $field->isRequired()} required{/if}{*
index 8546b03e2625791a9f9a23b7acfcee95e8ea6e45..7c433d646d35faf2de6808ccedb48e8dc2ad9f2e 100644 (file)
@@ -7,7 +7,9 @@ use wcf\system\form\builder\field\validation\FormFieldValidationError;
 use wcf\system\form\builder\IFormDocument;
 use wcf\system\form\builder\IFormNode;
 use wcf\system\language\I18nHandler;
+use wcf\system\language\LanguageFactory;
 use wcf\system\Regex;
+use wcf\system\WCF;
 use wcf\util\ArrayUtil;
 use wcf\util\StringUtil;
 
@@ -120,7 +122,19 @@ trait TI18nFormField {
                                return I18nHandler::getInstance()->getValue($this->getPrefixedId());
                        }
                        else if ($this->hasI18nValues()) {
-                               return I18nHandler::getInstance()->getValues($this->getPrefixedId());
+                               $values = I18nHandler::getInstance()->getValues($this->getPrefixedId());
+                               
+                               // handle legacy values from the past when multilingual values
+                               // were available
+                               if (count(LanguageFactory::getInstance()->getLanguages()) === 1) {
+                                       if (isset($values[WCF::getLanguage()->languageID])) {
+                                               return $values[WCF::getLanguage()->languageID];
+                                       }
+                                       
+                                       return current($values);
+                               }
+                               
+                               return $values;
                        }
                        
                        return '';