Home > database >  Is it possible to use CollectionType with LanguageType class ? Symfony
Is it possible to use CollectionType with LanguageType class ? Symfony

Time:09-09

I am trying to build a form and propose a language selection. I want this selection to duplicate when the user wants to add several languages.

My question is : Is it possible to use CollectionType with LanguageType class ?

Thank you.

CodePudding user response:

Yes, absolutely.

Check out one of the examples in the Docs:

$builder->add('emails', CollectionType::class, [
    // each entry in the array will be an "email" field
    'entry_type' => EmailType::class,
    // these options are passed to each "email" type
    'entry_options' => [
        'attr' => ['class' => 'email-box'],
    ],
]);

It is totally up to you to specify the underlying form type to be used, whether it is TextType or LanguageType. And you configure the type via the entry_options key.

Hope this helps...

  • Related