From 562f5e4394cdefa9a9a6de2b86119174e5c5cd50 Mon Sep 17 00:00:00 2001 From: Jules Pietri Date: Sat, 26 Mar 2016 02:34:58 +0100 Subject: [PATCH] [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`. --- .../Form/Extension/Core/Type/ChoiceType.php | 25 +------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php index 835f3767e5..26af37b9ac 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php @@ -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'],