Skip to content

Commit a5cdb07

Browse files
committed
[Form] remove useless code in ChoiceType
`ChoiceListFactoryInterface` expected `$group_by` to be a callable or null not an array. The factory defaults `group_by` to `ChoiceListInterface::getStructuredValues`.
1 parent 2e72aa0 commit a5cdb07

File tree

1 file changed

+1
-24
lines changed

1 file changed

+1
-24
lines changed

Extension/Core/Type/ChoiceType.php

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ public function configureOptions(OptionsResolver $resolver)
420420
$resolver->setAllowedTypes('choice_value', array('null', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath'));
421421
$resolver->setAllowedTypes('choice_attr', array('null', 'array', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath'));
422422
$resolver->setAllowedTypes('preferred_choices', array('array', '\Traversable', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath'));
423-
$resolver->setAllowedTypes('group_by', array('null', 'array', '\Traversable', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath'));
423+
$resolver->setAllowedTypes('group_by', array('null', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath'));
424424
}
425425

426426
/**
@@ -431,21 +431,6 @@ public function getName()
431431
return 'choice';
432432
}
433433

434-
private static function flipRecursive($choices, &$output = array())
435-
{
436-
foreach ($choices as $key => $value) {
437-
if (is_array($value)) {
438-
$output[$key] = array();
439-
self::flipRecursive($value, $output[$key]);
440-
continue;
441-
}
442-
443-
$output[$value] = $key;
444-
}
445-
446-
return $output;
447-
}
448-
449434
/**
450435
* Adds the sub fields for an expanded choice field.
451436
*
@@ -503,14 +488,6 @@ private function addSubForm(FormBuilderInterface $builder, $name, ChoiceView $ch
503488

504489
private function createChoiceListView(ChoiceListInterface $choiceList, array $options)
505490
{
506-
// If no explicit grouping information is given, use the structural
507-
// information from the "choices" option for creating groups
508-
if (!$options['group_by'] && $options['choices']) {
509-
$options['group_by'] = !$options['choices_as_values']
510-
? self::flipRecursive($options['choices'])
511-
: $options['choices'];
512-
}
513-
514491
return $this->choiceListFactory->createView(
515492
$choiceList,
516493
$options['preferred_choices'],

0 commit comments

Comments
 (0)