@@ -55,7 +55,9 @@ public function __construct(ChoiceListFactoryInterface $choiceListFactory = null
55
55
*/
56
56
public function buildForm (FormBuilderInterface $ builder , array $ options )
57
57
{
58
- if ('expanded ' == $ options ['widget ' ]) {
58
+ if (in_array ($ options ['widget ' ], array ('radio ' , 'checkbox ' ))) {
59
+ $ options ['multiple ' ] = 'checkbox ' == $ options ['widget ' ];
60
+
59
61
$ builder ->setDataMapper ($ options ['multiple ' ]
60
62
? new CheckboxListMapper ($ options ['choice_list ' ])
61
63
: new RadioListMapper ($ options ['choice_list ' ]));
@@ -178,7 +180,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
178
180
$ view ->vars = array_replace ($ view ->vars , array (
179
181
'widget ' => $ options ['widget ' ],
180
182
'multiple ' => $ options ['multiple ' ],
181
- 'expanded ' => $ options ['expanded ' ] , // BC
183
+ 'expanded ' => in_array ( $ options ['widget ' ], array ( ' radio ' , ' checkbox ' )) , // BC
182
184
'preferred_choices ' => $ choiceListView ->preferredChoices ,
183
185
'choices ' => $ choiceListView ->choices ,
184
186
'separator ' => '------------------- ' ,
@@ -225,7 +227,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
225
227
*/
226
228
public function finishView (FormView $ view , FormInterface $ form , array $ options )
227
229
{
228
- if (' expanded ' == $ options ['widget ' ]) {
230
+ if (in_array ( $ options ['widget ' ], array ( ' radio ' , ' checkbox ' )) ) {
229
231
// Radio buttons should have the same name as the parent
230
232
$ childName = $ view ->vars ['full_name ' ];
231
233
@@ -248,11 +250,15 @@ public function configureOptions(OptionsResolver $resolver)
248
250
$ choiceListFactory = $ this ->choiceListFactory ;
249
251
250
252
$ widget = function (Options $ options ) {
251
- return $ options ['expanded ' ] ? 'expanded ' : 'select ' ;
253
+ if ($ options ['expanded ' ]) {
254
+ return $ options ['multiple ' ] ? 'checkbox ' : 'radio ' ;
255
+ }
256
+
257
+ return 'select ' ;
252
258
};
253
259
254
260
$ emptyData = function (Options $ options ) {
255
- if ($ options ['multiple ' ] || $ options ['expanded ' ]) {
261
+ if ($ options ['multiple ' ] || ' checkbox ' == $ options ['widget ' ]) {
256
262
return array ();
257
263
}
258
264
@@ -304,7 +310,7 @@ public function configureOptions(OptionsResolver $resolver)
304
310
} elseif (false === $ placeholder ) {
305
311
// an empty value should be added but the user decided otherwise
306
312
return ;
307
- } elseif ($ options ['expanded ' ] && '' === $ placeholder ) {
313
+ } elseif (' radio ' == $ options ['widget ' ] && '' === $ placeholder ) {
308
314
// never use an empty label for radio buttons
309
315
return 'None ' ;
310
316
}
@@ -314,7 +320,7 @@ public function configureOptions(OptionsResolver $resolver)
314
320
};
315
321
316
322
$ compound = function (Options $ options ) {
317
- return ' expanded ' == $ options ['widget ' ];
323
+ return in_array ( $ options ['widget ' ], array ( ' radio ' , ' checkbox ' )) ;
318
324
};
319
325
320
326
$ choiceTranslationDomainNormalizer = function (Options $ options , $ choiceTranslationDomain ) {
@@ -368,6 +374,8 @@ public function configureOptions(OptionsResolver $resolver)
368
374
$ resolver ->setAllowedTypes ('choice_attr ' , array ('null ' , 'array ' , 'callable ' , 'string ' , 'Symfony\Component\PropertyAccess\PropertyPath ' ));
369
375
$ resolver ->setAllowedTypes ('preferred_choices ' , array ('array ' , '\Traversable ' , 'callable ' , 'string ' , 'Symfony\Component\PropertyAccess\PropertyPath ' ));
370
376
$ resolver ->setAllowedTypes ('group_by ' , array ('null ' , 'array ' , '\Traversable ' , 'string ' , 'callable ' , 'string ' , 'Symfony\Component\PropertyAccess\PropertyPath ' ));
377
+
378
+ $ resolver ->setAllowedValues ('widget ' , array ('select ' , 'radio ' , 'checkbox ' , 'text ' , 'hidden ' ));
371
379
}
372
380
373
381
/**
@@ -394,7 +402,7 @@ private static function flipRecursive($choices, &$output = array())
394
402
}
395
403
396
404
/**
397
- * Adds the sub fields for an expanded choice field.
405
+ * Adds the sub fields for a radio/checkbox choice field.
398
406
*
399
407
* @param FormBuilderInterface $builder The form builder.
400
408
* @param array $choiceViews The choice view objects.
0 commit comments