From 6b45d04156d0f111c9e14e6e33facee4ed5fc80d Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 22 Dec 2011 18:51:01 +0100 Subject: [PATCH] Fixed multiple language input i18n-inputs can now be declared optional and will no longer force a value, unless you left out one language. This means if i18n is not required you can leave out the value completely, but once you enable i18n you must give values for ALL installed languages! Fixes #235 Fixes #282 --- com.woltlab.wcf/option.xml | 3 +++ wcfsetup/install/files/js/WCF.js | 4 ++-- .../files/lib/system/language/I18nHandler.class.php | 7 ++++--- .../files/lib/system/option/TextI18nOptionType.class.php | 2 +- .../plugin/OptionPackageInstallationPlugin.class.php | 4 +++- wcfsetup/setup/db/install.sql | 1 + 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/com.woltlab.wcf/option.xml b/com.woltlab.wcf/option.xml index 306eceaffe..913abc6a06 100644 --- a/com.woltlab.wcf/option.xml +++ b/com.woltlab.wcf/option.xml @@ -128,11 +128,13 @@ general.page textI18n 1 + 1 diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 34eab02806..5f0d942711 100644 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -1820,7 +1820,7 @@ WCF.MultipleLanguageInput.prototype = { }, this)); // show list - this._list.show(); + this._list.addClass('open'); } }, @@ -1828,7 +1828,7 @@ WCF.MultipleLanguageInput.prototype = { * Closes the language selection. */ _closeSelection: function() { - this._list.hide(); + this._list.removeClass('open'); }, /** diff --git a/wcfsetup/install/files/lib/system/language/I18nHandler.class.php b/wcfsetup/install/files/lib/system/language/I18nHandler.class.php index 3452da2b38..1f75c7c992 100644 --- a/wcfsetup/install/files/lib/system/language/I18nHandler.class.php +++ b/wcfsetup/install/files/lib/system/language/I18nHandler.class.php @@ -121,15 +121,16 @@ class I18nHandler extends SingletonFactory { * Returns false, if element value is not empty. * * @param string $elementID + * @param boolean $requireI18n * @return boolean */ - public function validateValue($elementID) { + public function validateValue($elementID, $requireI18n) { if ($this->isPlainValue($elementID)) { - if ($this->getValue($elementID) == '') { + if ($requireI18n && $this->getValue($elementID) == '') { return false; } } - else if (!isset($this->i18nValues[$elementID]) || empty($this->i18nValues[$elementID])) { + else if ($requireI18n && (!isset($this->i18nValues[$elementID]) || empty($this->i18nValues[$elementID]))) { return false; } else { diff --git a/wcfsetup/install/files/lib/system/option/TextI18nOptionType.class.php b/wcfsetup/install/files/lib/system/option/TextI18nOptionType.class.php index 855208c0e1..8b0392f175 100644 --- a/wcfsetup/install/files/lib/system/option/TextI18nOptionType.class.php +++ b/wcfsetup/install/files/lib/system/option/TextI18nOptionType.class.php @@ -40,7 +40,7 @@ class TextI18nOptionType extends TextOptionType { * @see wcf\system\option\IOptionType::validate() */ public function validate(Option $option, $newValue) { - if (!I18nHandler::getInstance()->validateValue($option->optionName)) { + if (!I18nHandler::getInstance()->validateValue($option->optionName, $option->requireI18n)) { throw new UserInputException($option->optionName, 'validationFailed'); } } diff --git a/wcfsetup/install/files/lib/system/package/plugin/OptionPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/OptionPackageInstallationPlugin.class.php index e4a264cfce..eeb71f9a26 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/OptionPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/OptionPackageInstallationPlugin.class.php @@ -31,7 +31,7 @@ class OptionPackageInstallationPlugin extends AbstractOptionPackageInstallationP // default values $optionName = $optionType = $defaultValue = $validationPattern = $selectOptions = $enableOptions = $permissions = $options = ''; $showOrder = null; - $hidden = $supportI18n = 0; + $hidden = $supportI18n = $optionalI18n = 0; // get values if (isset($option['name'])) $optionName = $option['name']; @@ -46,6 +46,7 @@ class OptionPackageInstallationPlugin extends AbstractOptionPackageInstallationP if (isset($option['permissions'])) $permissions = $option['permissions']; if (isset($option['options'])) $options = $option['options']; if (isset($option['supporti18n'])) $supportI18n = $option['supporti18n']; + if (isset($option['optionali18n'])) $optionalI18n = $option['optionali18n']; // check if optionType exists $className = 'wcf\system\option\\'.StringUtil::firstCharToUpperCase($optionType).'OptionType'; @@ -71,6 +72,7 @@ class OptionPackageInstallationPlugin extends AbstractOptionPackageInstallationP 'permissions' => $permissions, 'options' => $options, 'supportI18n' => $supportI18n, + 'optionalI18n' => $optionalI18n, 'additionalData' => serialize($additionalData) ); diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index 7221f33b4d..29ecf6b71a 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -258,6 +258,7 @@ CREATE TABLE wcf1_option ( permissions TEXT, options TEXT, supportI18n TINYINT(1) NOT NULL DEFAULT 0, + requireI18n TINYINT(1) NOT NULL DEFAULT 0, additionalData MEDIUMTEXT, UNIQUE KEY optionName (optionName, packageID) ); -- 2.20.1