From 83c91a3d9dc35f5b06918a36798aebc49f873081 Mon Sep 17 00:00:00 2001 From: William DURAND Date: Tue, 24 Jul 2012 18:42:05 +0200 Subject: [PATCH] Add support for nested form types --- Parser/FormTypeParser.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Parser/FormTypeParser.php b/Parser/FormTypeParser.php index a2bcbca..8f62eab 100644 --- a/Parser/FormTypeParser.php +++ b/Parser/FormTypeParser.php @@ -55,12 +55,22 @@ class FormTypeParser if (is_string($type) && class_exists($type)) { $type = new $type(); } + $form = $this->formFactory->create($type); + return $this->parseForm($form); + } + + private function parseForm($form, $prefix = null) + { $parameters = array(); foreach ($form as $name => $child) { $config = $child->getConfig(); + if ($prefix) { + $name = sprintf('%s[%s]', $prefix, $name); + } + $bestType = ''; for ($type = $config->getType(); null !== $type; $type = $type->getParent()) { if (isset($this->mapTypes[$type->getName()])) { @@ -68,6 +78,17 @@ class FormTypeParser } } + if ('' === $bestType) { + if ($type = $config->getType()) { + if ($type = $type->getInnerType()) { + $subForm = $this->formFactory->create($type); + $parameters = array_merge($parameters, $this->parseForm($subForm, $name)); + + continue; + } + } + } + $parameters[$name] = array( 'dataType' => $bestType, 'required' => $config->getRequired(),