Fix mixed boolean operators in condition in `TI18nFormField::validate()`
authorMatthias Schmidt <gravatronics@live.com>
Fri, 5 Feb 2021 10:33:03 +0000 (11:33 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Fri, 5 Feb 2021 10:33:03 +0000 (11:33 +0100)
… and improve the preceding comment.

See #3926

wcfsetup/install/files/lib/system/form/builder/field/TI18nFormField.class.php

index 7c433d646d35faf2de6808ccedb48e8dc2ad9f2e..2bebce1be751f9c1d9326034d29c4a8c0485e963 100644 (file)
@@ -398,9 +398,11 @@ trait TI18nFormField {
         * nodes are valid. A `IFormField` object is valid if its value is valid.
         */
        public function validate() {
-               // if i18n is required for a non-required field and the field is
-               // empty, that is no error
-               if ($this->isI18n() && (!empty(ArrayUtil::trim($this->getValue()))) || $this->isRequired()) {
+               // If i18n is required for a non-required field and the field is
+               // empty in all languages, `I18nHandler::validateValue()` will mark
+               // as invalid even though it is a valid state for this form field,
+               // thus the additional condition.
+               if ($this->isI18n() && (!empty(ArrayUtil::trim($this->getValue())) || $this->isRequired())) {
                        if (!I18nHandler::getInstance()->validateValue($this->getPrefixedId(), $this->isI18nRequired(), !$this->isRequired())) {
                                if ($this->hasPlainValue()) {
                                        $this->addValidationError(new FormFieldValidationError('empty'));