2525class FormValidator extends ConstraintValidator
2626{
2727 private $ resolvedGroups ;
28- private $ fieldFormConstraints ;
2928
3029 /**
3130 * {@inheritdoc}
@@ -68,7 +67,6 @@ public function validate($form, Constraint $formConstraint)
6867
6968 if ($ hasChildren && $ form ->isRoot ()) {
7069 $ this ->resolvedGroups = new \SplObjectStorage ();
71- $ this ->fieldFormConstraints = [];
7270 }
7371
7472 if ($ groups instanceof GroupSequence) {
@@ -93,7 +91,6 @@ public function validate($form, Constraint $formConstraint)
9391 $ this ->resolvedGroups [$ field ] = (array ) $ group ;
9492 $ fieldFormConstraint = new Form ();
9593 $ fieldFormConstraint ->groups = $ group ;
96- $ this ->fieldFormConstraints [] = $ fieldFormConstraint ;
9794 $ this ->context ->setNode ($ this ->context ->getValue (), $ field , $ this ->context ->getMetadata (), $ this ->context ->getPropertyPath ());
9895 $ validator ->atPath (sprintf ('children[%s] ' , $ field ->getName ()))->validate ($ field , $ fieldFormConstraint , $ group );
9996 }
@@ -139,18 +136,15 @@ public function validate($form, Constraint $formConstraint)
139136 foreach ($ form ->all () as $ field ) {
140137 if ($ field ->isSubmitted ()) {
141138 $ this ->resolvedGroups [$ field ] = $ groups ;
142- $ fieldFormConstraint = new Form ();
143- $ this ->fieldFormConstraints [] = $ fieldFormConstraint ;
144139 $ this ->context ->setNode ($ this ->context ->getValue (), $ field , $ this ->context ->getMetadata (), $ this ->context ->getPropertyPath ());
145- $ validator ->atPath (sprintf ('children[%s] ' , $ field ->getName ()))->validate ($ field , $ fieldFormConstraint );
140+ $ validator ->atPath (sprintf ('children[%s] ' , $ field ->getName ()))->validate ($ field , $ formConstraint );
146141 }
147142 }
148143 }
149144
150145 if ($ hasChildren && $ form ->isRoot ()) {
151146 // destroy storage to avoid memory leaks
152147 $ this ->resolvedGroups = new \SplObjectStorage ();
153- $ this ->fieldFormConstraints = [];
154148 }
155149 } elseif (!$ form ->isSynchronized ()) {
156150 $ childrenSynchronized = true ;
@@ -159,11 +153,8 @@ public function validate($form, Constraint $formConstraint)
159153 foreach ($ form as $ child ) {
160154 if (!$ child ->isSynchronized ()) {
161155 $ childrenSynchronized = false ;
162-
163- $ fieldFormConstraint = new Form ();
164- $ this ->fieldFormConstraints [] = $ fieldFormConstraint ;
165156 $ this ->context ->setNode ($ this ->context ->getValue (), $ child , $ this ->context ->getMetadata (), $ this ->context ->getPropertyPath ());
166- $ validator ->atPath (sprintf ('children[%s] ' , $ child ->getName ()))->validate ($ child , $ fieldFormConstraint );
157+ $ validator ->atPath (sprintf ('children[%s] ' , $ child ->getName ()))->validate ($ child , $ formConstraint );
167158 }
168159 }
169160
0 commit comments