How to embed a precharged collection of non-entity forms in symfony2
Per the documentation on Using a Form Without a Class, the bound data is just an array.
If you don't do either of these, then the form will return the data as an array. In this example, since
$defaultData
is not an object (and nodata_class
option is set),$form->getData()
ultimately returns an array.
And to clear up any misconception you might have about form data - the underlying object/class of a form type does not have to be an Entity - you can use any class with public properties or getters/setters that map to the form fields. For that matter, Entity classes are nothing special themselves - they just have a bunch of mapping information that tells the ORM how to persist them.
But, back to your original question, I don't know what your ChildFormType looks like, but let's assume it has two fields, sequence
and title
$form->add('aclAccess', 'collection', array( 'type' => new ChildFormType(), 'allow_add' => true, 'mapped' => false, 'data' => array( array('sequence' => 1, 'title' => 'Foo') , array('sequence' => 2, 'title' => 'Bar') ) ));
That should do the trick