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 0dd72cd

Browse filesBrowse files
Merge branch '2.7' into 2.8
* 2.7: [Bridge/Twig] Fix lowest form dep [Form] Fix tests and reference usage Conflicts: src/Symfony/Bridge/Twig/composer.json
2 parents ff2addc + beb8525 commit 0dd72cd
Copy full SHA for 0dd72cd

File tree

Expand file treeCollapse file tree

1 file changed

+22
-21
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+22
-21
lines changed

‎src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
+22-21Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public function finishView(FormView $view, FormInterface $form, array $options)
238238
*/
239239
public function configureOptions(OptionsResolver $resolver)
240240
{
241-
$choiceLabels = array();
241+
$choiceLabels = (object) array('labels' => array());
242242
$choiceListFactory = $this->choiceListFactory;
243243

244244
$emptyData = function (Options $options) {
@@ -254,9 +254,9 @@ public function configureOptions(OptionsResolver $resolver)
254254
};
255255

256256
// BC closure, to be removed in 3.0
257-
$choicesNormalizer = function (Options $options, $choices) use (&$choiceLabels) {
257+
$choicesNormalizer = function (Options $options, $choices) use ($choiceLabels) {
258258
// Unset labels from previous invocations
259-
$choiceLabels = array();
259+
$choiceLabels->labels = array();
260260

261261
// This closure is irrelevant when "choices_as_values" is set to true
262262
if ($options['choices_as_values']) {
@@ -269,22 +269,23 @@ public function configureOptions(OptionsResolver $resolver)
269269
};
270270

271271
// BC closure, to be removed in 3.0
272-
$choiceLabel = function (Options $options) use (&$choiceLabels) {
272+
$choiceLabel = function (Options $options) use ($choiceLabels) {
273273
// If the choices contain duplicate labels, the normalizer of the
274274
// "choices" option stores them in the $choiceLabels variable
275275

276276
// Trigger the normalizer
277277
$options->offsetGet('choices');
278278

279279
// Pick labels from $choiceLabels if available
280-
// Don't invoke count() to avoid creating a copy of the array (yet)
281-
if ($choiceLabels) {
280+
if ($choiceLabels->labels) {
282281
// Don't pass the labels by reference. We do want to create a
283282
// copy here so that every form has an own version of that
284-
// variable (contrary to the global reference shared by all
283+
// variable (contrary to the $choiceLabels object shared by all
285284
// forms)
286-
return function ($choice, $key) use ($choiceLabels) {
287-
return $choiceLabels[$key];
285+
$labels = $choiceLabels->labels;
286+
287+
return function ($choice, $key) use ($labels) {
288+
return $labels[$key];
288289
};
289290
}
290291

@@ -519,26 +520,26 @@ private function createChoiceListView(ChoiceListInterface $choiceList, array $op
519520
* are lost. Store them in a utility array that is used from the
520521
* "choice_label" closure by default.
521522
*
522-
* @param array $choices The choice labels indexed by choices.
523-
* Labels are replaced by generated keys.
524-
* @param array $choiceLabels The array that receives the choice labels
525-
* indexed by generated keys.
526-
* @param int|null $nextKey The next generated key.
523+
* @param array $choices The choice labels indexed by choices.
524+
* Labels are replaced by generated keys.
525+
* @param object $choiceLabels The object that receives the choice labels
526+
* indexed by generated keys.
527+
* @param int $nextKey The next generated key.
527528
*
528529
* @internal Public only to be accessible from closures on PHP 5.3. Don't
529-
* use this method, as it may be removed without notice.
530+
* use this method as it may be removed without notice and will be in 3.0.
530531
*/
531-
public static function normalizeLegacyChoices(array &$choices, array &$choiceLabels, &$nextKey = 0)
532+
public static function normalizeLegacyChoices(array &$choices, $choiceLabels, &$nextKey = 0)
532533
{
533-
foreach ($choices as $choice => &$choiceLabel) {
534+
foreach ($choices as $choice => $choiceLabel) {
534535
if (is_array($choiceLabel)) {
535-
self::normalizeLegacyChoices($choiceLabel, $choiceLabels, $nextKey);
536+
$choiceLabel = ''; // Dereference $choices[$choice]
537+
self::normalizeLegacyChoices($choices[$choice], $choiceLabels, $nextKey);
536538
continue;
537539
}
538540

539-
$choiceLabels[$nextKey] = $choiceLabel;
540-
$choices[$choice] = $nextKey;
541-
++$nextKey;
541+
$choiceLabels->labels[$nextKey] = $choiceLabel;
542+
$choices[$choice] = $nextKey++;
542543
}
543544
}
544545
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.