@@ -131,44 +131,46 @@ public function mapViolation(ConstraintViolation $violation, FormInterface $form
131
131
132
132
// Only add the error if the form is synchronized
133
133
if ($ this ->acceptsErrors ($ scope )) {
134
- $ labelFormat = $ scope ->getConfig ()->getOption ('label_format ' );
135
-
136
- if (null !== $ labelFormat ) {
137
- $ label = str_replace (
138
- [
139
- '%name% ' ,
140
- '%id% ' ,
141
- ],
142
- [
143
- $ scope ->getName (),
144
- (string ) $ scope ->getPropertyPath (),
145
- ],
146
- $ labelFormat
147
- );
148
- } else {
149
- $ label = $ scope ->getConfig ()->getOption ('label ' );
150
- }
151
-
152
- if (null === $ label && null !== $ this ->formRenderer ) {
153
- $ label = $ this ->formRenderer ->humanize ($ scope ->getName ());
154
- } elseif (null === $ label ) {
155
- $ label = $ scope ->getName ();
156
- }
157
-
158
- if (false !== $ label && null !== $ this ->translator ) {
159
- $ label = $ this ->translator ->trans (
160
- $ label ,
161
- $ scope ->getConfig ()->getOption ('label_translation_parameters ' , []),
162
- $ scope ->getConfig ()->getOption ('translation_domain ' )
163
- );
164
- }
165
-
166
134
$ message = $ violation ->getMessage ();
167
135
$ messageTemplate = $ violation ->getMessageTemplate ();
168
136
169
- if (false !== $ label ) {
170
- $ message = str_replace ('{{ label }} ' , $ label , $ message );
171
- $ messageTemplate = str_replace ('{{ label }} ' , $ label , $ messageTemplate );
137
+ if (false !== strpos ($ message , '{{ label }} ' ) || false !== strpos ($ messageTemplate , '{{ label }} ' )) {
138
+ $ labelFormat = $ scope ->getConfig ()->getOption ('label_format ' );
139
+
140
+ if (null !== $ labelFormat ) {
141
+ $ label = str_replace (
142
+ [
143
+ '%name% ' ,
144
+ '%id% ' ,
145
+ ],
146
+ [
147
+ $ scope ->getName (),
148
+ (string ) $ scope ->getPropertyPath (),
149
+ ],
150
+ $ labelFormat
151
+ );
152
+ } else {
153
+ $ label = $ scope ->getConfig ()->getOption ('label ' );
154
+ }
155
+
156
+ if (false !== $ label ) {
157
+ if (null === $ label && null !== $ this ->formRenderer ) {
158
+ $ label = $ this ->formRenderer ->humanize ($ scope ->getName ());
159
+ } elseif (null === $ label ) {
160
+ $ label = $ scope ->getName ();
161
+ }
162
+
163
+ if (null !== $ this ->translator ) {
164
+ $ label = $ this ->translator ->trans (
165
+ $ label ,
166
+ $ scope ->getConfig ()->getOption ('label_translation_parameters ' , []),
167
+ $ scope ->getConfig ()->getOption ('translation_domain ' )
168
+ );
169
+ }
170
+
171
+ $ message = str_replace ('{{ label }} ' , $ label , $ message );
172
+ $ messageTemplate = str_replace ('{{ label }} ' , $ label , $ messageTemplate );
173
+ }
172
174
}
173
175
174
176
$ scope ->addError (new FormError (
0 commit comments