@@ -238,7 +238,7 @@ public function finishView(FormView $view, FormInterface $form, array $options)
238
238
*/
239
239
public function configureOptions (OptionsResolver $ resolver )
240
240
{
241
- $ choiceLabels = array ();
241
+ $ choiceLabels = ( object ) array (' labels ' => array () );
242
242
$ choiceListFactory = $ this ->choiceListFactory ;
243
243
244
244
$ emptyData = function (Options $ options ) {
@@ -254,9 +254,9 @@ public function configureOptions(OptionsResolver $resolver)
254
254
};
255
255
256
256
// BC closure, to be removed in 3.0
257
- $ choicesNormalizer = function (Options $ options , $ choices ) use (& $ choiceLabels ) {
257
+ $ choicesNormalizer = function (Options $ options , $ choices ) use ($ choiceLabels ) {
258
258
// Unset labels from previous invocations
259
- $ choiceLabels = array ();
259
+ $ choiceLabels-> labels = array ();
260
260
261
261
// This closure is irrelevant when "choices_as_values" is set to true
262
262
if ($ options ['choices_as_values ' ]) {
@@ -269,22 +269,23 @@ public function configureOptions(OptionsResolver $resolver)
269
269
};
270
270
271
271
// BC closure, to be removed in 3.0
272
- $ choiceLabel = function (Options $ options ) use (& $ choiceLabels ) {
272
+ $ choiceLabel = function (Options $ options ) use ($ choiceLabels ) {
273
273
// If the choices contain duplicate labels, the normalizer of the
274
274
// "choices" option stores them in the $choiceLabels variable
275
275
276
276
// Trigger the normalizer
277
277
$ options ->offsetGet ('choices ' );
278
278
279
279
// 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 ) {
282
281
// Don't pass the labels by reference. We do want to create a
283
282
// 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
285
284
// 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 ];
288
289
};
289
290
}
290
291
@@ -519,26 +520,26 @@ private function createChoiceListView(ChoiceListInterface $choiceList, array $op
519
520
* are lost. Store them in a utility array that is used from the
520
521
* "choice_label" closure by default.
521
522
*
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.
527
528
*
528
529
* @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 .
530
531
*/
531
- public static function normalizeLegacyChoices (array &$ choices , array & $ choiceLabels , &$ nextKey = 0 )
532
+ public static function normalizeLegacyChoices (array &$ choices , $ choiceLabels , &$ nextKey = 0 )
532
533
{
533
- foreach ($ choices as $ choice => & $ choiceLabel ) {
534
+ foreach ($ choices as $ choice => $ choiceLabel ) {
534
535
if (is_array ($ choiceLabel )) {
535
- self ::normalizeLegacyChoices ($ choiceLabel , $ choiceLabels , $ nextKey );
536
+ $ choiceLabel = '' ; // Dereference $choices[$choice]
537
+ self ::normalizeLegacyChoices ($ choices [$ choice ], $ choiceLabels , $ nextKey );
536
538
continue ;
537
539
}
538
540
539
- $ choiceLabels [$ nextKey ] = $ choiceLabel ;
540
- $ choices [$ choice ] = $ nextKey ;
541
- ++$ nextKey ;
541
+ $ choiceLabels ->labels [$ nextKey ] = $ choiceLabel ;
542
+ $ choices [$ choice ] = $ nextKey ++;
542
543
}
543
544
}
544
545
}
0 commit comments