@@ -97,7 +97,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
9797 if ($ options ['expanded ' ] || $ options ['multiple ' ]) {
9898 // Make sure that scalar, submitted values are converted to arrays
9999 // 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 ) {
101101 $ form = $ event ->getForm ();
102102 $ data = $ event ->getData ();
103103
@@ -166,16 +166,17 @@ public function buildForm(FormBuilderInterface $builder, array $options)
166166
167167 if ($ options ['multiple ' ]) {
168168 $ messageTemplate = $ options ['invalid_message ' ] ?? 'The value {{ value }} is not valid. ' ;
169+ $ translator = $ this ->translator ;
169170
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 ) {
171172 // Throw exception if unknown values were submitted
172173 if (\count ($ unknownValues ) > 0 ) {
173174 $ form = $ event ->getForm ();
174175
175176 $ clientDataAsString = \is_scalar ($ form ->getViewData ()) ? (string ) $ form ->getViewData () : (\is_array ($ form ->getViewData ()) ? implode ('", " ' , array_keys ($ unknownValues )) : \gettype ($ form ->getViewData ()));
176177
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 ' );
179180 } else {
180181 $ message = strtr ($ messageTemplate , ['{{ value }} ' => $ clientDataAsString ]);
181182 }
@@ -199,7 +200,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
199200
200201 // To avoid issues when the submitted choices are arrays (i.e. array to string conversions),
201202 // 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 ) {
203204 $ data = $ event ->getData ();
204205
205206 if (!\is_array ($ data )) {
@@ -245,9 +246,9 @@ public function buildView(FormView $view, FormInterface $form, array $options)
245246 // closure here that is optimized for the value of the form, to
246247 // avoid making the type check inside the closure.
247248 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 );
249250 } else {
250- $ view ->vars ['is_selected ' ] = fn ($ choice , $ value ) => $ choice === $ value ;
251+ $ view ->vars ['is_selected ' ] = static fn ($ choice , $ value ) => $ choice === $ value ;
251252 }
252253
253254 // Check if the choices already contain the empty value
@@ -285,7 +286,7 @@ public function finishView(FormView $view, FormInterface $form, array $options)
285286
286287 public function configureOptions (OptionsResolver $ resolver )
287288 {
288- $ emptyData = function (Options $ options ) {
289+ $ emptyData = static function (Options $ options ) {
289290 if ($ options ['expanded ' ] && !$ options ['multiple ' ]) {
290291 return null ;
291292 }
@@ -297,9 +298,9 @@ public function configureOptions(OptionsResolver $resolver)
297298 return '' ;
298299 };
299300
300- $ placeholderDefault = fn (Options $ options ) => $ options ['required ' ] ? null : '' ;
301+ $ placeholderDefault = static fn (Options $ options ) => $ options ['required ' ] ? null : '' ;
301302
302- $ placeholderNormalizer = function (Options $ options , $ placeholder ) {
303+ $ placeholderNormalizer = static function (Options $ options , $ placeholder ) {
303304 if ($ options ['multiple ' ]) {
304305 // never use an empty value for this case
305306 return null ;
@@ -318,9 +319,9 @@ public function configureOptions(OptionsResolver $resolver)
318319 return $ placeholder ;
319320 };
320321
321- $ compound = fn (Options $ options ) => $ options ['expanded ' ];
322+ $ compound = static fn (Options $ options ) => $ options ['expanded ' ];
322323
323- $ choiceTranslationDomainNormalizer = function (Options $ options , $ choiceTranslationDomain ) {
324+ $ choiceTranslationDomainNormalizer = static function (Options $ options , $ choiceTranslationDomain ) {
324325 if (true === $ choiceTranslationDomain ) {
325326 return $ options ['translation_domain ' ];
326327 }
0 commit comments