From fbe948896338acb8aeccfadee2da2fff0f080c24 Mon Sep 17 00:00:00 2001
From: David de Boer <david@ddeboer.nl>
Date: Wed, 23 Oct 2013 15:45:30 +0200
Subject: [PATCH] Add support for embedded forms

---
 Parser/FormTypeParser.php           |  6 +++++
 Tests/Parser/FormTypeParserTest.php | 42 ++++++++++++++++++++++++++---
 2 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/Parser/FormTypeParser.php b/Parser/FormTypeParser.php
index 2a018de..e089432 100644
--- a/Parser/FormTypeParser.php
+++ b/Parser/FormTypeParser.php
@@ -102,6 +102,12 @@ class FormTypeParser implements ParserInterface
                 } elseif ('collection' === $type->getName()) {
                     if (is_string($config->getOption('type')) && isset($this->mapTypes[$config->getOption('type')])) {
                         $bestType = sprintf('array of %ss', $this->mapTypes[$config->getOption('type')]);
+                    } else {
+                        // Embedded form collection
+                        $subParameters = $this->parseForm($this->formFactory->create($config->getOption('type')), $name . '[]');
+                        $parameters = array_merge($parameters, $subParameters);
+
+                        continue 2;
                     }
                 }
             }
diff --git a/Tests/Parser/FormTypeParserTest.php b/Tests/Parser/FormTypeParserTest.php
index b2ee201..4705ca4 100644
--- a/Tests/Parser/FormTypeParserTest.php
+++ b/Tests/Parser/FormTypeParserTest.php
@@ -64,9 +64,21 @@ class FormTypeParserTest extends \PHPUnit_Framework_TestCase
                         'description' => '',
                         'readonly' => false
                     ),
-                    'collection_type[b]' => array(
+                    'collection_type[b][][a]' => array(
                         'dataType' => 'string',
                         'required' => true,
+                        'description' => 'A nice description',
+                        'readonly' => false
+                    ),
+                    'collection_type[b][][b]' => array(
+                        'dataType' => 'string',
+                        'required' => true,
+                        'description' => '',
+                        'readonly' => false
+                    ),
+                    'collection_type[b][][c]' => array(
+                        'dataType' => 'boolean',
+                        'required' => true,
                         'description' => '',
                         'readonly' => false
                     )
@@ -84,9 +96,21 @@ class FormTypeParserTest extends \PHPUnit_Framework_TestCase
                         'description' => '',
                         'readonly' => false
                     ),
-                    'b' => array(
+                    'b[][a]' => array(
                         'dataType' => 'string',
                         'required' => true,
+                        'description' => 'A nice description',
+                        'readonly' => false
+                    ),
+                    'b[][b]' => array(
+                        'dataType' => 'string',
+                        'required' => true,
+                        'description' => '',
+                        'readonly' => false
+                    ),
+                    'b[][c]' => array(
+                        'dataType' => 'boolean',
+                        'required' => true,
                         'description' => '',
                         'readonly' => false
                     )
@@ -104,9 +128,21 @@ class FormTypeParserTest extends \PHPUnit_Framework_TestCase
                         'description' => '',
                         'readonly' => false
                     ),
-                    'b' => array(
+                    'b[][a]' => array(
                         'dataType' => 'string',
                         'required' => true,
+                        'description' => 'A nice description',
+                        'readonly' => false
+                    ),
+                    'b[][b]' => array(
+                        'dataType' => 'string',
+                        'required' => true,
+                        'description' => '',
+                        'readonly' => false
+                    ),
+                    'b[][c]' => array(
+                        'dataType' => 'boolean',
+                        'required' => true,
                         'description' => '',
                         'readonly' => false
                     )