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