@@ -209,19 +209,15 @@ public function collectViewVariables(FormView $view)
209
209
*/
210
210
public function buildPreliminaryFormTree (FormInterface $ form )
211
211
{
212
- $ this ->data ['forms ' ][$ form ->getName ()] = array ();
213
-
214
- $ this ->recursiveBuildPreliminaryFormTree ($ form , $ this ->data ['forms ' ][$ form ->getName ()], $ this ->data ['forms_by_hash ' ]);
212
+ $ this ->data ['forms ' ][$ form ->getName ()] = &$ this ->recursiveBuildPreliminaryFormTree ($ form , $ this ->data ['forms_by_hash ' ]);
215
213
}
216
214
217
215
/**
218
216
* {@inheritdoc}
219
217
*/
220
218
public function buildFinalFormTree (FormInterface $ form , FormView $ view )
221
219
{
222
- $ this ->data ['forms ' ][$ form ->getName ()] = array ();
223
-
224
- $ this ->recursiveBuildFinalFormTree ($ form , $ view , $ this ->data ['forms ' ][$ form ->getName ()], $ this ->data ['forms_by_hash ' ]);
220
+ $ this ->data ['forms ' ][$ form ->getName ()] = &$ this ->recursiveBuildFinalFormTree ($ form , $ view , $ this ->data ['forms_by_hash ' ]);
225
221
}
226
222
227
223
/**
@@ -354,26 +350,25 @@ protected function cloneVar($var, $isClass = false)
354
350
return $ cache = $ this ->cloner ->cloneVar ($ var );
355
351
}
356
352
357
- private function recursiveBuildPreliminaryFormTree (FormInterface $ form, & $ output , array &$ outputByHash )
353
+ private function & recursiveBuildPreliminaryFormTree (FormInterface $ form , array &$ outputByHash )
358
354
{
359
355
$ hash = spl_object_hash ($ form );
360
356
357
+ $ output = &$ outputByHash [$ hash ];
361
358
$ output = isset ($ this ->dataByForm [$ hash ])
362
359
? $ this ->dataByForm [$ hash ]
363
360
: array ();
364
361
365
- $ outputByHash [$ hash ] = &$ output ;
366
-
367
362
$ output ['children ' ] = array ();
368
363
369
364
foreach ($ form as $ name => $ child ) {
370
- $ output ['children ' ][$ name ] = array ();
371
-
372
- $ this ->recursiveBuildPreliminaryFormTree ($ child , $ output ['children ' ][$ name ], $ outputByHash );
365
+ $ output ['children ' ][$ name ] = &$ this ->recursiveBuildPreliminaryFormTree ($ child , $ outputByHash );
373
366
}
367
+
368
+ return $ output ;
374
369
}
375
370
376
- private function recursiveBuildFinalFormTree (FormInterface $ form = null , FormView $ view, & $ output , array &$ outputByHash )
371
+ private function & recursiveBuildFinalFormTree (FormInterface $ form = null , FormView $ view , array &$ outputByHash )
377
372
{
378
373
$ viewHash = spl_object_hash ($ view );
379
374
$ formHash = null ;
@@ -386,6 +381,9 @@ private function recursiveBuildFinalFormTree(FormInterface $form = null, FormVie
386
381
// corresponding FormInterface instance for its view in a different way
387
382
$ formHash = $ this ->formsByView [$ viewHash ];
388
383
}
384
+ if (null !== $ formHash ) {
385
+ $ output = &$ outputByHash [$ formHash ];
386
+ }
389
387
390
388
$ output = isset ($ this ->dataByView [$ viewHash ])
391
389
? $ this ->dataByView [$ viewHash ]
@@ -398,8 +396,6 @@ private function recursiveBuildFinalFormTree(FormInterface $form = null, FormVie
398
396
? $ this ->dataByForm [$ formHash ]
399
397
: array ()
400
398
);
401
-
402
- $ outputByHash [$ formHash ] = &$ output ;
403
399
}
404
400
405
401
$ output ['children ' ] = array ();
@@ -411,9 +407,9 @@ private function recursiveBuildFinalFormTree(FormInterface $form = null, FormVie
411
407
? $ form ->get ($ name )
412
408
: null ;
413
409
414
- $ output ['children ' ][$ name ] = array ();
415
-
416
- $ this ->recursiveBuildFinalFormTree ($ childForm , $ childView , $ output ['children ' ][$ name ], $ outputByHash );
410
+ $ output ['children ' ][$ name ] = &$ this ->recursiveBuildFinalFormTree ($ childForm , $ childView , $ outputByHash );
417
411
}
412
+
413
+ return $ output ;
418
414
}
419
415
}
0 commit comments