2525class FormValidator extends ConstraintValidator
2626{
2727 private $ resolvedGroups ;
28+ private $ fieldFormConstraints ;
2829
2930 /**
3031 * {@inheritdoc}
@@ -67,6 +68,7 @@ public function validate($form, Constraint $formConstraint)
6768
6869 if ($ hasChildren && $ form ->isRoot ()) {
6970 $ this ->resolvedGroups = new \SplObjectStorage ();
71+ $ this ->fieldFormConstraints = [];
7072 }
7173
7274 if ($ groups instanceof GroupSequence) {
@@ -84,14 +86,16 @@ public function validate($form, Constraint $formConstraint)
8486
8587 foreach ($ form ->all () as $ field ) {
8688 if ($ field ->isSubmitted ()) {
87- // remember to validate this field is one group only
89+ // remember to validate this field in one group only
8890 // otherwise resolving the groups would reuse the same
8991 // sequence recursively, thus some fields could fail
9092 // in different steps without breaking early enough
9193 $ this ->resolvedGroups [$ field ] = (array ) $ group ;
9294 $ fieldFormConstraint = new Form ();
95+ $ fieldFormConstraint ->groups = $ group ;
96+ $ this ->fieldFormConstraints [] = $ fieldFormConstraint ;
9397 $ this ->context ->setNode ($ this ->context ->getValue (), $ field , $ this ->context ->getMetadata (), $ this ->context ->getPropertyPath ());
94- $ validator ->atPath (sprintf ('children[%s] ' , $ field ->getName ()))->validate ($ field , $ fieldFormConstraint );
98+ $ validator ->atPath (sprintf ('children[%s] ' , $ field ->getName ()))->validate ($ field , $ fieldFormConstraint, $ group );
9599 }
96100 }
97101
@@ -130,6 +134,7 @@ public function validate($form, Constraint $formConstraint)
130134 if ($ field ->isSubmitted ()) {
131135 $ this ->resolvedGroups [$ field ] = $ groups ;
132136 $ fieldFormConstraint = new Form ();
137+ $ this ->fieldFormConstraints [] = $ fieldFormConstraint ;
133138 $ this ->context ->setNode ($ this ->context ->getValue (), $ field , $ this ->context ->getMetadata (), $ this ->context ->getPropertyPath ());
134139 $ validator ->atPath (sprintf ('children[%s] ' , $ field ->getName ()))->validate ($ field , $ fieldFormConstraint );
135140 }
@@ -139,6 +144,7 @@ public function validate($form, Constraint $formConstraint)
139144 if ($ hasChildren && $ form ->isRoot ()) {
140145 // destroy storage to avoid memory leaks
141146 $ this ->resolvedGroups = new \SplObjectStorage ();
147+ $ this ->fieldFormConstraints = [];
142148 }
143149 } elseif (!$ form ->isSynchronized ()) {
144150 $ childrenSynchronized = true ;
@@ -149,6 +155,7 @@ public function validate($form, Constraint $formConstraint)
149155 $ childrenSynchronized = false ;
150156
151157 $ fieldFormConstraint = new Form ();
158+ $ this ->fieldFormConstraints [] = $ fieldFormConstraint ;
152159 $ this ->context ->setNode ($ this ->context ->getValue (), $ child , $ this ->context ->getMetadata (), $ this ->context ->getPropertyPath ());
153160 $ validator ->atPath (sprintf ('children[%s] ' , $ child ->getName ()))->validate ($ child , $ fieldFormConstraint );
154161 }
0 commit comments