25
25
class FormValidator extends ConstraintValidator
26
26
{
27
27
private $ resolvedGroups ;
28
+ private $ fieldFormConstraints ;
28
29
29
30
/**
30
31
* {@inheritdoc}
@@ -67,6 +68,7 @@ public function validate($form, Constraint $formConstraint)
67
68
68
69
if ($ hasChildren && $ form ->isRoot ()) {
69
70
$ this ->resolvedGroups = new \SplObjectStorage ();
71
+ $ this ->fieldFormConstraints = [];
70
72
}
71
73
72
74
if ($ groups instanceof GroupSequence) {
@@ -84,14 +86,16 @@ public function validate($form, Constraint $formConstraint)
84
86
85
87
foreach ($ form ->all () as $ field ) {
86
88
if ($ field ->isSubmitted ()) {
87
- // remember to validate this field is one group only
89
+ // remember to validate this field in one group only
88
90
// otherwise resolving the groups would reuse the same
89
91
// sequence recursively, thus some fields could fail
90
92
// in different steps without breaking early enough
91
93
$ this ->resolvedGroups [$ field ] = (array ) $ group ;
92
94
$ fieldFormConstraint = new Form ();
95
+ $ fieldFormConstraint ->groups = $ group ;
96
+ $ this ->fieldFormConstraints [] = $ fieldFormConstraint ;
93
97
$ 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 );
95
99
}
96
100
}
97
101
@@ -136,6 +140,7 @@ public function validate($form, Constraint $formConstraint)
136
140
if ($ field ->isSubmitted ()) {
137
141
$ this ->resolvedGroups [$ field ] = $ groups ;
138
142
$ fieldFormConstraint = new Form ();
143
+ $ this ->fieldFormConstraints [] = $ fieldFormConstraint ;
139
144
$ this ->context ->setNode ($ this ->context ->getValue (), $ field , $ this ->context ->getMetadata (), $ this ->context ->getPropertyPath ());
140
145
$ validator ->atPath (sprintf ('children[%s] ' , $ field ->getName ()))->validate ($ field , $ fieldFormConstraint );
141
146
}
@@ -145,6 +150,7 @@ public function validate($form, Constraint $formConstraint)
145
150
if ($ hasChildren && $ form ->isRoot ()) {
146
151
// destroy storage to avoid memory leaks
147
152
$ this ->resolvedGroups = new \SplObjectStorage ();
153
+ $ this ->fieldFormConstraints = [];
148
154
}
149
155
} elseif (!$ form ->isSynchronized ()) {
150
156
$ childrenSynchronized = true ;
@@ -155,6 +161,7 @@ public function validate($form, Constraint $formConstraint)
155
161
$ childrenSynchronized = false ;
156
162
157
163
$ fieldFormConstraint = new Form ();
164
+ $ this ->fieldFormConstraints [] = $ fieldFormConstraint ;
158
165
$ this ->context ->setNode ($ this ->context ->getValue (), $ child , $ this ->context ->getMetadata (), $ this ->context ->getPropertyPath ());
159
166
$ validator ->atPath (sprintf ('children[%s] ' , $ child ->getName ()))->validate ($ child , $ fieldFormConstraint );
160
167
}
0 commit comments