@@ -263,9 +263,7 @@ public function configureOptions(OptionsResolver $resolver)
263
263
return $ choices ;
264
264
}
265
265
266
- ChoiceType::normalizeLegacyChoices ($ choices , $ choiceLabels );
267
-
268
- return $ choices ;
266
+ return ChoiceType::normalizeLegacyChoices ($ choices , $ choiceLabels );
269
267
};
270
268
271
269
// BC closure, to be removed in 3.0
@@ -520,26 +518,30 @@ private function createChoiceListView(ChoiceListInterface $choiceList, array $op
520
518
* are lost. Store them in a utility array that is used from the
521
519
* "choice_label" closure by default.
522
520
*
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.
521
+ * @param array|\Traversable $choices The choice labels indexed by choices.
522
+ * @param object $choiceLabels The object that receives the choice labels
523
+ * indexed by generated keys.
524
+ * @param int $nextKey The next generated key.
525
+ *
526
+ * @return array The choices in a normalized array with labels replaced by generated keys.
528
527
*
529
528
* @internal Public only to be accessible from closures on PHP 5.3. Don't
530
529
* use this method as it may be removed without notice and will be in 3.0.
531
530
*/
532
- public static function normalizeLegacyChoices (array & $ choices , $ choiceLabels , &$ nextKey = 0 )
531
+ public static function normalizeLegacyChoices ($ choices , $ choiceLabels , &$ nextKey = 0 )
533
532
{
533
+ $ normalizedChoices = array ();
534
+
534
535
foreach ($ choices as $ choice => $ choiceLabel ) {
535
- if (is_array ($ choiceLabel )) {
536
- $ choiceLabel = '' ; // Dereference $choices[$choice]
537
- self ::normalizeLegacyChoices ($ choices [$ choice ], $ choiceLabels , $ nextKey );
536
+ if (is_array ($ choiceLabel ) || $ choiceLabel instanceof \Traversable) {
537
+ $ normalizedChoices [$ choice ] = self ::normalizeLegacyChoices ($ choiceLabel , $ choiceLabels , $ nextKey );
538
538
continue ;
539
539
}
540
540
541
541
$ choiceLabels ->labels [$ nextKey ] = $ choiceLabel ;
542
- $ choices [$ choice ] = $ nextKey ++;
542
+ $ normalizedChoices [$ choice ] = $ nextKey ++;
543
543
}
544
+
545
+ return $ normalizedChoices ;
544
546
}
545
547
}
0 commit comments