Move custom validator calls out of `AbstractFormField::validate()`
authorMatthias Schmidt <gravatronics@live.com>
Mon, 7 May 2018 18:05:45 +0000 (20:05 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Mon, 7 May 2018 18:05:45 +0000 (20:05 +0200)
… to ensure that they are always executed after the form field’s
internal validation (which could not be guaranteed due to inheritance).

See #2545

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

index 73dc7f7a938ebbbde79304ac4cd175186d886558..9f01c5c39721b142113f4fdece4e6eeb68b68505 100644 (file)
@@ -294,6 +294,16 @@ trait TFormParentNode {
                                }
                                
                                $child->validate();
+                               
+                               if ($child instanceof IFormField && empty($child->getValidationErrors())) {
+                                       foreach ($child->getValidators() as $validator) {
+                                               $validator($child);
+                                               
+                                               if (!empty($child->getValidationErrors())) {
+                                                       break;
+                                               }
+                                       }
+                               }
                        }
                }
        }
index 9d2f95c71e98aab07bcaef6ca9073a127301ca95..16ff1d4a2e862d3c361031deb4613966eb7326bd 100644 (file)
@@ -240,14 +240,6 @@ abstract class AbstractFormField implements IFormField {
         * @inheritDoc
         */
        public function validate() {
-               if (empty($this->getValidationErrors())) {
-                       foreach ($this->getValidators() as $validator) {
-                               $validator($this);
-                               
-                               if (!empty($this->getValidationErrors())) {
-                                       break;
-                               }
-                       }
-               }
+               // does nothing
        }
 }