SYMFONY FormTypeCollection with various fields

In my project I would like to be able to add a Collection on a Form. I thought about the FormTypeCollection. But the thing is, I need something like that:
A "New" button, at the end of the form and everytime you click on the new, a "mini-form" is added and you have the three input to fill: "name,text,link". I would like it to be stored in the database as artists = [name,text,link] for example. I have no idea how to do that. i don’t want to add an Entity Artist because I just need this for display and I don’t need it to be stored as an Entity on the database.
My code right now is like that:

protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->with('Contenu')
            ->add('published', CheckboxType::class, ['required' => false, 'label' => 'Publier'])
            ->add('title', TextType::class, ['required' => true, 'label' => 'Titre'])
            ->add('marketingEtiquette', TextType::class, ['required' => false, 'label' => 'Etiquette Marketing'])
            ->add('textLink', TextType::class, ['required' => true, 'label' => 'Texte du lien'])
            ->add('shoppingLink', TextType::class, ['required' => true, 'label' => 'Lien'])
            ->add('media', ElFinderType::class, array(
                'label' => 'Photo',
                'instance' => 'form',
                'enable' => true,
                'required' => true,
                'attr' => array('class' => 'form-control')
                )
            )
            ->add('position',ChoiceType::class, array(
                'label' => 'Position dans la page',
                'choices' => array(
                    'Bloc Artistes' => 'artists',
                    'Bloc haut de page' => 'top',
                    'Bloc bas de page' => 'bottom'
                )
            ))
            ->add('artists',CollectionType::class,array(
                'label' => 'Les artistes',
                'allow_add' => true,
            ))
            ->end();
    }

I don’t know how to add 3 fields to the field artists and generate them on the add button click. i don’t even know if it’s possible actually. I also don’t know what should be the type ‘artists’ in the database.

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

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