@@ -99,22 +99,39 @@ public function validate($form, Constraint $constraint)
99
99
? (string ) $ form ->getViewData ()
100
100
: gettype ($ form ->getViewData ());
101
101
102
- $ this ->buildViolation ($ config ->getOption ('invalid_message ' ))
103
- ->setParameters (array_replace (array ('{{ value }} ' => $ clientDataAsString ), $ config ->getOption ('invalid_message_parameters ' )))
104
- ->setInvalidValue ($ form ->getViewData ())
105
- ->setCode (Form::NOT_SYNCHRONIZED_ERROR )
106
- ->setCause ($ form ->getTransformationFailure ())
107
- ->addViolation ();
102
+ if ($ this ->context instanceof ExecutionContextInterface) {
103
+ $ this ->context ->buildViolation ($ config ->getOption ('invalid_message ' ))
104
+ ->setParameters (array_replace (array ('{{ value }} ' => $ clientDataAsString ), $ config ->getOption ('invalid_message_parameters ' )))
105
+ ->setInvalidValue ($ form ->getViewData ())
106
+ ->setCode (Form::NOT_SYNCHRONIZED_ERROR )
107
+ ->setCause ($ form ->getTransformationFailure ())
108
+ ->addViolation ();
109
+ } else {
110
+ $ this ->buildViolation ($ config ->getOption ('invalid_message ' ))
111
+ ->setParameters (array_replace (array ('{{ value }} ' => $ clientDataAsString ), $ config ->getOption ('invalid_message_parameters ' )))
112
+ ->setInvalidValue ($ form ->getViewData ())
113
+ ->setCode (Form::NOT_SYNCHRONIZED_ERROR )
114
+ ->setCause ($ form ->getTransformationFailure ())
115
+ ->addViolation ();
116
+ }
108
117
}
109
118
}
110
119
111
120
// Mark the form with an error if it contains extra fields
112
121
if (!$ config ->getOption ('allow_extra_fields ' ) && count ($ form ->getExtraData ()) > 0 ) {
113
- $ this ->buildViolation ($ config ->getOption ('extra_fields_message ' ))
114
- ->setParameter ('{{ extra_fields }} ' , implode ('", " ' , array_keys ($ form ->getExtraData ())))
115
- ->setInvalidValue ($ form ->getExtraData ())
116
- ->setCode (Form::NO_SUCH_FIELD_ERROR )
117
- ->addViolation ();
122
+ if ($ this ->context instanceof ExecutionContextInterface) {
123
+ $ this ->context ->buildViolation ($ config ->getOption ('extra_fields_message ' ))
124
+ ->setParameter ('{{ extra_fields }} ' , implode ('", " ' , array_keys ($ form ->getExtraData ())))
125
+ ->setInvalidValue ($ form ->getExtraData ())
126
+ ->setCode (Form::NO_SUCH_FIELD_ERROR )
127
+ ->addViolation ();
128
+ } else {
129
+ $ this ->buildViolation ($ config ->getOption ('extra_fields_message ' ))
130
+ ->setParameter ('{{ extra_fields }} ' , implode ('", " ' , array_keys ($ form ->getExtraData ())))
131
+ ->setInvalidValue ($ form ->getExtraData ())
132
+ ->setCode (Form::NO_SUCH_FIELD_ERROR )
133
+ ->addViolation ();
134
+ }
118
135
}
119
136
}
120
137
0 commit comments