Search code examples
phpformssymfonyarraycollection

Embed form in ArrayCollection Symfony2


I have form:

enter image description here

My code to Tag1 look like:

$builder
        ->add('tag1', 'collection', [
            'type'   => 'text',
            'label' => 'Tag1',
            'allow_add'         => true,
            'allow_delete'      => true,
            'prototype'         => true,
            'options'           =>
                [
                    'required'  => false,
                    'label'     => false
                ]
        ])

But how add Sub form in field? Thanks!


Solution

  • Hi i think it's quite simple.

    $builder
        ->add('tag1', 'collection', [
            'type' => new yourSubFormType(),
            ...
        ])
    

    more information : http://symfony.com/doc/current/cookbook/form/form_collections.html