So I understand how to make a custom form class return one instance of an entity, as shown in this code taken from the Symfony2 docs:
public function getDefaultOptions(array $options)
{
return array(
'data_class' => 'Acme\TaskBundle\Entity\Category',
);
}
But what if I want the form to return an array of Category entities? How would I do that?
You have to use the collection type. See the documentation about the collection type. You have to specify the type of which the collection is built, then it will return an array of that entity. In the type you have to declare the data_class as you did above. And of course your form will contain multiple subforms of that type.