Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1dbaed7

Browse filesBrowse files
committed
minor #18316 [Form] remove useless copy in ChoiceType (HeahDude)
This PR was merged into the 2.7 branch. Discussion ---------- [Form] remove useless copy in ChoiceType | Q | A | ------------- | --- | Branch? | 2.7+ | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | symfony/symfony-docs#6393 `ChoiceListFactoryInterface` expected `$groupBy` to be a callable or null, not an array ([ref](https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Form/ChoiceList/Factory/ChoiceListFactoryInterface.php#L111)). The factory defaults `groupBy` to `ChoiceListInterface::getStructuredValues()` ([ref](https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php#L122)). Hence, the copy of the choices array and the recursive flip are useless and may be slowing down performances imho (especially with `EntityType`). Commits ------- 562f5e4 [Form] remove useless code in ChoiceType
2 parents be6d2c2 + a5cdb07 commit 1dbaed7
Copy full SHA for 1dbaed7

File tree

Expand file treeCollapse file tree

1 file changed

+1
-24
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+1
-24
lines changed

‎Extension/Core/Type/ChoiceType.php

Copy file name to clipboardExpand all lines: Extension/Core/Type/ChoiceType.php
+1-24Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.