CorentinDy
CorentinDy

Reputation: 63

Symfony send options from FormType CollectionType to FormType

I would like to know if there is any way to send an option from a form type with CollectionType to another form type.

$builder->add(
    'contact', CollectionType::class,
    [
        'entry_type' => ContactType::class,
        'data' => [
            'options' => 'confirmResa'
        ]
    ]
);

I know we can send option with this data by using $builder->getData() in the second form type but when it's a CollectionType, I think it take the data for him instead of using it for the entry_type.

Upvotes: 2

Views: 717

Answers (1)

CorentinDy
CorentinDy

Reputation: 63

Ok nevermind I find a solution, I've already use in my last project.

So the answer is to use entry_options and sending data in the entry_options

cf: http://symfony.com/doc/current/reference/forms/types/collection.html#entry-options

Solution:

$builder->add('contact', CollectionType::class, [
    'entry_type' => ContactType::class, 
    'entry_options' => ['data' => ['confirmResa']],
]);

Upvotes: 1

Related Questions