25
25
class FormValidator extends ConstraintValidator
26
26
{
27
27
private $ resolvedGroups ;
28
- private $ fieldFormConstraints ;
29
28
30
29
/**
31
30
* {@inheritdoc}
@@ -68,7 +67,6 @@ public function validate($form, Constraint $formConstraint)
68
67
69
68
if ($ hasChildren && $ form ->isRoot ()) {
70
69
$ this ->resolvedGroups = new \SplObjectStorage ();
71
- $ this ->fieldFormConstraints = [];
72
70
}
73
71
74
72
if ($ groups instanceof GroupSequence) {
@@ -93,7 +91,6 @@ public function validate($form, Constraint $formConstraint)
93
91
$ this ->resolvedGroups [$ field ] = (array ) $ group ;
94
92
$ fieldFormConstraint = new Form ();
95
93
$ fieldFormConstraint ->groups = $ group ;
96
- $ this ->fieldFormConstraints [] = $ fieldFormConstraint ;
97
94
$ this ->context ->setNode ($ this ->context ->getValue (), $ field , $ this ->context ->getMetadata (), $ this ->context ->getPropertyPath ());
98
95
$ validator ->atPath (sprintf ('children[%s] ' , $ field ->getName ()))->validate ($ field , $ fieldFormConstraint , $ group );
99
96
}
@@ -139,18 +136,15 @@ public function validate($form, Constraint $formConstraint)
139
136
foreach ($ form ->all () as $ field ) {
140
137
if ($ field ->isSubmitted ()) {
141
138
$ this ->resolvedGroups [$ field ] = $ groups ;
142
- $ fieldFormConstraint = new Form ();
143
- $ this ->fieldFormConstraints [] = $ fieldFormConstraint ;
144
139
$ 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 );
146
141
}
147
142
}
148
143
}
149
144
150
145
if ($ hasChildren && $ form ->isRoot ()) {
151
146
// destroy storage to avoid memory leaks
152
147
$ this ->resolvedGroups = new \SplObjectStorage ();
153
- $ this ->fieldFormConstraints = [];
154
148
}
155
149
} elseif (!$ form ->isSynchronized ()) {
156
150
$ childrenSynchronized = true ;
@@ -159,11 +153,8 @@ public function validate($form, Constraint $formConstraint)
159
153
foreach ($ form as $ child ) {
160
154
if (!$ child ->isSynchronized ()) {
161
155
$ childrenSynchronized = false ;
162
-
163
- $ fieldFormConstraint = new Form ();
164
- $ this ->fieldFormConstraints [] = $ fieldFormConstraint ;
165
156
$ 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 );
167
158
}
168
159
}
169
160
0 commit comments