@@ -97,7 +97,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
97
97
if ($ options ['expanded ' ] || $ options ['multiple ' ]) {
98
98
// Make sure that scalar, submitted values are converted to arrays
99
99
// which can be submitted to the checkboxes/radio buttons
100
- $ builder ->addEventListener (FormEvents::PRE_SUBMIT , function (FormEvent $ event ) use ($ choiceList , $ options , &$ unknownValues ) {
100
+ $ builder ->addEventListener (FormEvents::PRE_SUBMIT , static function (FormEvent $ event ) use ($ choiceList , $ options , &$ unknownValues ) {
101
101
$ form = $ event ->getForm ();
102
102
$ data = $ event ->getData ();
103
103
@@ -166,16 +166,17 @@ public function buildForm(FormBuilderInterface $builder, array $options)
166
166
167
167
if ($ options ['multiple ' ]) {
168
168
$ messageTemplate = $ options ['invalid_message ' ] ?? 'The value {{ value }} is not valid. ' ;
169
+ $ translator = $ this ->translator ;
169
170
170
- $ builder ->addEventListener (FormEvents::POST_SUBMIT , function (FormEvent $ event ) use (&$ unknownValues , $ messageTemplate ) {
171
+ $ builder ->addEventListener (FormEvents::POST_SUBMIT , static function (FormEvent $ event ) use (&$ unknownValues , $ messageTemplate, $ translator ) {
171
172
// Throw exception if unknown values were submitted
172
173
if (\count ($ unknownValues ) > 0 ) {
173
174
$ form = $ event ->getForm ();
174
175
175
176
$ clientDataAsString = \is_scalar ($ form ->getViewData ()) ? (string ) $ form ->getViewData () : (\is_array ($ form ->getViewData ()) ? implode ('", " ' , array_keys ($ unknownValues )) : \gettype ($ form ->getViewData ()));
176
177
177
- if (null !== $ this -> translator ) {
178
- $ message = $ this -> translator ->trans ($ messageTemplate , ['{{ value }} ' => $ clientDataAsString ], 'validators ' );
178
+ if ($ translator ) {
179
+ $ message = $ translator ->trans ($ messageTemplate , ['{{ value }} ' => $ clientDataAsString ], 'validators ' );
179
180
} else {
180
181
$ message = strtr ($ messageTemplate , ['{{ value }} ' => $ clientDataAsString ]);
181
182
}
@@ -199,7 +200,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
199
200
200
201
// To avoid issues when the submitted choices are arrays (i.e. array to string conversions),
201
202
// we have to ensure that all elements of the submitted choice data are NULL, strings or ints.
202
- $ builder ->addEventListener (FormEvents::PRE_SUBMIT , function (FormEvent $ event ) {
203
+ $ builder ->addEventListener (FormEvents::PRE_SUBMIT , static function (FormEvent $ event ) {
203
204
$ data = $ event ->getData ();
204
205
205
206
if (!\is_array ($ data )) {
@@ -245,9 +246,9 @@ public function buildView(FormView $view, FormInterface $form, array $options)
245
246
// closure here that is optimized for the value of the form, to
246
247
// avoid making the type check inside the closure.
247
248
if ($ options ['multiple ' ]) {
248
- $ view ->vars ['is_selected ' ] = fn ($ choice , array $ values ) => \in_array ($ choice , $ values , true );
249
+ $ view ->vars ['is_selected ' ] = static fn ($ choice , array $ values ) => \in_array ($ choice , $ values , true );
249
250
} else {
250
- $ view ->vars ['is_selected ' ] = fn ($ choice , $ value ) => $ choice === $ value ;
251
+ $ view ->vars ['is_selected ' ] = static fn ($ choice , $ value ) => $ choice === $ value ;
251
252
}
252
253
253
254
// Check if the choices already contain the empty value
@@ -285,7 +286,7 @@ public function finishView(FormView $view, FormInterface $form, array $options)
285
286
286
287
public function configureOptions (OptionsResolver $ resolver )
287
288
{
288
- $ emptyData = function (Options $ options ) {
289
+ $ emptyData = static function (Options $ options ) {
289
290
if ($ options ['expanded ' ] && !$ options ['multiple ' ]) {
290
291
return null ;
291
292
}
@@ -297,9 +298,9 @@ public function configureOptions(OptionsResolver $resolver)
297
298
return '' ;
298
299
};
299
300
300
- $ placeholderDefault = fn (Options $ options ) => $ options ['required ' ] ? null : '' ;
301
+ $ placeholderDefault = static fn (Options $ options ) => $ options ['required ' ] ? null : '' ;
301
302
302
- $ placeholderNormalizer = function (Options $ options , $ placeholder ) {
303
+ $ placeholderNormalizer = static function (Options $ options , $ placeholder ) {
303
304
if ($ options ['multiple ' ]) {
304
305
// never use an empty value for this case
305
306
return null ;
@@ -318,9 +319,9 @@ public function configureOptions(OptionsResolver $resolver)
318
319
return $ placeholder ;
319
320
};
320
321
321
- $ compound = fn (Options $ options ) => $ options ['expanded ' ];
322
+ $ compound = static fn (Options $ options ) => $ options ['expanded ' ];
322
323
323
- $ choiceTranslationDomainNormalizer = function (Options $ options , $ choiceTranslationDomain ) {
324
+ $ choiceTranslationDomainNormalizer = static function (Options $ options , $ choiceTranslationDomain ) {
324
325
if (true === $ choiceTranslationDomain ) {
325
326
return $ options ['translation_domain ' ];
326
327
}
0 commit comments