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
@@ -136,6 +140,7 @@ public function validate($form, Constraint $formConstraint)
136140 if ($ field ->isSubmitted ()) {
137141 $ this ->resolvedGroups [$ field ] = $ groups ;
138142 $ fieldFormConstraint = new Form ();
143+ $ this ->fieldFormConstraints [] = $ fieldFormConstraint ;
139144 $ this ->context ->setNode ($ this ->context ->getValue (), $ field , $ this ->context ->getMetadata (), $ this ->context ->getPropertyPath ());
140145 $ validator ->atPath (sprintf ('children[%s] ' , $ field ->getName ()))->validate ($ field , $ fieldFormConstraint );
141146 }
@@ -145,6 +150,7 @@ public function validate($form, Constraint $formConstraint)
145150 if ($ hasChildren && $ form ->isRoot ()) {
146151 // destroy storage to avoid memory leaks
147152 $ this ->resolvedGroups = new \SplObjectStorage ();
153+ $ this ->fieldFormConstraints = [];
148154 }
149155 } elseif (!$ form ->isSynchronized ()) {
150156 $ childrenSynchronized = true ;
@@ -155,6 +161,7 @@ public function validate($form, Constraint $formConstraint)
155161 $ childrenSynchronized = false ;
156162
157163 $ fieldFormConstraint = new Form ();
164+ $ this ->fieldFormConstraints [] = $ fieldFormConstraint ;
158165 $ this ->context ->setNode ($ this ->context ->getValue (), $ child , $ this ->context ->getMetadata (), $ this ->context ->getPropertyPath ());
159166 $ validator ->atPath (sprintf ('children[%s] ' , $ child ->getName ()))->validate ($ child , $ fieldFormConstraint );
160167 }
0 commit comments