@@ -263,9 +263,11 @@ public function configureOptions(OptionsResolver $resolver)
263
263
return $ choices ;
264
264
}
265
265
266
- ChoiceType::normalizeLegacyChoices ($ choices , $ choiceLabels );
266
+ if (null === $ choices ) {
267
+ return ;
268
+ }
267
269
268
- return $ choices ;
270
+ return ChoiceType:: normalizeLegacyChoices ( $ choices, $ choiceLabels ) ;
269
271
};
270
272
271
273
// BC closure, to be removed in 3.0
@@ -503,26 +505,30 @@ private function createChoiceListView(ChoiceListInterface $choiceList, array $op
503
505
* are lost. Store them in a utility array that is used from the
504
506
* "choice_label" closure by default.
505
507
*
506
- * @param array $choices The choice labels indexed by choices.
507
- * Labels are replaced by generated keys.
508
- * @param object $choiceLabels The object that receives the choice labels
509
- * indexed by generated keys.
510
- * @param int $nextKey The next generated key.
508
+ * @param array|\Traversable $choices The choice labels indexed by choices.
509
+ * @param object $choiceLabels The object that receives the choice labels
510
+ * indexed by generated keys.
511
+ * @param int $nextKey The next generated key.
512
+ *
513
+ * @return array The choices in a normalized array with labels replaced by generated keys.
511
514
*
512
515
* @internal Public only to be accessible from closures on PHP 5.3. Don't
513
516
* use this method as it may be removed without notice and will be in 3.0.
514
517
*/
515
- public static function normalizeLegacyChoices (array & $ choices , $ choiceLabels , &$ nextKey = 0 )
518
+ public static function normalizeLegacyChoices ($ choices , $ choiceLabels , &$ nextKey = 0 )
516
519
{
520
+ $ normalizedChoices = array ();
521
+
517
522
foreach ($ choices as $ choice => $ choiceLabel ) {
518
- if (is_array ($ choiceLabel )) {
519
- $ choiceLabel = '' ; // Dereference $choices[$choice]
520
- self ::normalizeLegacyChoices ($ choices [$ choice ], $ choiceLabels , $ nextKey );
523
+ if (is_array ($ choiceLabel ) || $ choiceLabel instanceof \Traversable) {
524
+ $ normalizedChoices [$ choice ] = self ::normalizeLegacyChoices ($ choiceLabel , $ choiceLabels , $ nextKey );
521
525
continue ;
522
526
}
523
527
524
528
$ choiceLabels ->labels [$ nextKey ] = $ choiceLabel ;
525
- $ choices [$ choice ] = $ nextKey ++;
529
+ $ normalizedChoices [$ choice ] = $ nextKey ++;
526
530
}
531
+
532
+ return $ normalizedChoices ;
527
533
}
528
534
}
0 commit comments