[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:
parent
66c99826ce
commit
562f5e4394
|
@ -420,7 +420,7 @@ class ChoiceType extends AbstractType
|
||||||
$resolver->setAllowedTypes('choice_value', array('null', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath'));
|
$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('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('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';
|
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.
|
* Adds the sub fields for an expanded choice field.
|
||||||
*
|
*
|
||||||
|
@ -503,14 +488,6 @@ class ChoiceType extends AbstractType
|
||||||
|
|
||||||
private function createChoiceListView(ChoiceListInterface $choiceList, array $options)
|
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(
|
return $this->choiceListFactory->createView(
|
||||||
$choiceList,
|
$choiceList,
|
||||||
$options['preferred_choices'],
|
$options['preferred_choices'],
|
||||||
|
|
Reference in New Issue