Skip to content

Commit 164a20c

Browse files
[Form] Fix FormDataCollector
1 parent 8c22de4 commit 164a20c

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

src/Symfony/Component/Form/Extension/DataCollector/FormDataCollector.php

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -209,19 +209,15 @@ public function collectViewVariables(FormView $view)
209209
*/
210210
public function buildPreliminaryFormTree(FormInterface $form)
211211
{
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']);
215213
}
216214

217215
/**
218216
* {@inheritdoc}
219217
*/
220218
public function buildFinalFormTree(FormInterface $form, FormView $view)
221219
{
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']);
225221
}
226222

227223
/**
@@ -354,26 +350,25 @@ protected function cloneVar($var, $isClass = false)
354350
return $cache = $this->cloner->cloneVar($var);
355351
}
356352

357-
private function recursiveBuildPreliminaryFormTree(FormInterface $form, &$output, array &$outputByHash)
353+
private function &recursiveBuildPreliminaryFormTree(FormInterface $form, array &$outputByHash)
358354
{
359355
$hash = spl_object_hash($form);
360356

357+
$output = &$outputByHash[$hash];
361358
$output = isset($this->dataByForm[$hash])
362359
? $this->dataByForm[$hash]
363360
: array();
364361

365-
$outputByHash[$hash] = &$output;
366-
367362
$output['children'] = array();
368363

369364
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);
373366
}
367+
368+
return $output;
374369
}
375370

376-
private function recursiveBuildFinalFormTree(FormInterface $form = null, FormView $view, &$output, array &$outputByHash)
371+
private function &recursiveBuildFinalFormTree(FormInterface $form = null, FormView $view, array &$outputByHash)
377372
{
378373
$viewHash = spl_object_hash($view);
379374
$formHash = null;
@@ -386,6 +381,9 @@ private function recursiveBuildFinalFormTree(FormInterface $form = null, FormVie
386381
// corresponding FormInterface instance for its view in a different way
387382
$formHash = $this->formsByView[$viewHash];
388383
}
384+
if (null !== $formHash) {
385+
$output = &$outputByHash[$formHash];
386+
}
389387

390388
$output = isset($this->dataByView[$viewHash])
391389
? $this->dataByView[$viewHash]
@@ -398,8 +396,6 @@ private function recursiveBuildFinalFormTree(FormInterface $form = null, FormVie
398396
? $this->dataByForm[$formHash]
399397
: array()
400398
);
401-
402-
$outputByHash[$formHash] = &$output;
403399
}
404400

405401
$output['children'] = array();
@@ -411,9 +407,9 @@ private function recursiveBuildFinalFormTree(FormInterface $form = null, FormVie
411407
? $form->get($name)
412408
: null;
413409

414-
$output['children'][$name] = array();
415-
416-
$this->recursiveBuildFinalFormTree($childForm, $childView, $output['children'][$name], $outputByHash);
410+
$output['children'][$name] = &$this->recursiveBuildFinalFormTree($childForm, $childView, $outputByHash);
417411
}
412+
413+
return $output;
418414
}
419415
}

0 commit comments

Comments
 (0)