[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`.
This commit is contained in:
Jules Pietri 2016-03-26 02:34:58 +01:00
parent 66c99826ce
commit 562f5e4394
1 changed files with 1 additions and 24 deletions

View File

@ -420,7 +420,7 @@ class ChoiceType extends AbstractType
$resolver->setAllowedTypes('choice_value', array('null', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath'));
$resolver->setAllowedTypes('choice_attr', array('null', 'array', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath'));
$resolver->setAllowedTypes('preferred_choices', array('array', '\Traversable', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath'));
$resolver->setAllowedTypes('group_by', array('null', 'array', '\Traversable', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath'));
$resolver->setAllowedTypes('group_by', array('null', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath'));
}
/**
@ -431,21 +431,6 @@ class ChoiceType extends AbstractType
return 'choice';
}
private static function flipRecursive($choices, &$output = array())
{
foreach ($choices as $key => $value) {
if (is_array($value)) {
$output[$key] = array();
self::flipRecursive($value, $output[$key]);
continue;
}
$output[$value] = $key;
}
return $output;
}
/**
* Adds the sub fields for an expanded choice field.
*
@ -503,14 +488,6 @@ class ChoiceType extends AbstractType
private function createChoiceListView(ChoiceListInterface $choiceList, array $options)
{
// If no explicit grouping information is given, use the structural
// information from the "choices" option for creating groups
if (!$options['group_by'] && $options['choices']) {
$options['group_by'] = !$options['choices_as_values']
? self::flipRecursive($options['choices'])
: $options['choices'];
}
return $this->choiceListFactory->createView(
$choiceList,
$options['preferred_choices'],