Quellcode durchsuchen

[Form] fixed forms grouped validation

Added ability to specify **match-all** validation group, which
constraints will runs on every specified validation group.
Added groups="*" option to `Form::data` Valid validator.
ever.zet vor 14 Jahren
Ursprung
Commit
4c340c5cc9

+ 3 - 1
src/Symfony/Component/Form/Resources/config/validation.xml

@@ -17,7 +17,9 @@
 
   <class name="Symfony\Component\Form\Form">
     <getter property="data">
-      <constraint name="Valid" />
+      <constraint name="Valid">
+        <option name="groups">*</option>
+      </constraint>
     </getter>
     <getter property="postMaxSizeReached">
       <constraint name="AssertFalse">

+ 9 - 3
src/Symfony/Component/Validator/Mapping/ElementMetadata.php

@@ -87,7 +87,7 @@ abstract class ElementMetadata
     }
 
     /**
-     * Returns the constraints of the given group.
+     * Returns the constraints of the given group and global ones (* group).
      *
      * @param string $group The group name
      *
@@ -95,8 +95,14 @@ abstract class ElementMetadata
      */
     public function findConstraints($group)
     {
-        return isset($this->constraintsByGroup[$group])
+        $globalConstraints  = isset($this->constraintsByGroup['*'])
+                ? $this->constraintsByGroup['*']
+                : array();
+
+        $groupConstraints   = isset($this->constraintsByGroup[$group])
                 ? $this->constraintsByGroup[$group]
                 : array();
+
+        return array_merge((array) $globalConstraints, (array) $groupConstraints);
     }
-}
+}