Symfony: How to allow the user to add a Subcollection of Forms to a Form

I already asked this question in detail for my Problem here but did not get an answer, because it is probably to long so i try to ask this a little more abstract and short.

So in this Symfony documentation it is described how to let the User add new Tags to the CollectionType Task by adding a line 'allow_add' => true, to the $builder->add()-Method and the data-prototype to the Tag as well as some Javascript Code.
But what if i have another CollectionType which holds all the Tasks (lets call this TaskHolder) and you want to make the user to be able to add a completely new Task?

You probably start by creating a new class:

// src/AppBundle/Form/Type/TaskType.php
namespace AppBundleFormType;

use AppBundleEntityTask;
use SymfonyComponentFormAbstractType;
use SymfonyComponentFormFormBuilderInterface;
use SymfonyComponentOptionsResolverOptionsResolver;
use SymfonyComponentFormExtensionCoreTypeCollectionType;

class TaskType extends AbstractType
    public function buildForm(FormBuilderInterface $builder, array $options)

        $builder->add('tags', CollectionType::class, array(
            'entry_type' => TagType::class,
            'entry_options' => array('label' => false),

    public function configureOptions(OptionsResolver $resolver)
            'data_class' => Task::class,

But where do you put the prototype then?
If you are able to answer this question you could maybe have a look at my specific Problem as well.
I have really no clue how to do this and i’m trying for more than a week now.
If you think it just isn’t possible you can let me know to but pleeease just answer something 🙁

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *