infinite-networks / InfiniteFormBundle

A collection of useful form types and extensions for Symfony.
169 stars 40 forks source link

Add "types_options" options (allow to pass specific options to subtypes) #62

Closed plfort closed 8 years ago

plfort commented 8 years ago

This PR allows to pass specific form options to subtypes by a new options called "types_options", this is an associative array with "type" as key and an array as value:

$builder->add('resources',PolyCollectionType::class,
            [
                'types' => [
                    ImageResourceFormType::class,
                    LinkResourceFormType::class,
                ],
                'types_options'=>[
                    ImageResourceFormType::class=>[
                        'my_option'=>'hello'
                    ]
                ]
            ]);
     // ImageResourceFormType
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class'=>ImageResource::class,
            'model_class' => ImageResource::class
        ]);

        $resolver->setRequired('my_option');
    }

The "types_options" is used only if it is defined (not empty), otherwhise the default behaviour is used with the "options" key.

jmclean commented 8 years ago

Works great. Thanks!

murilolobato commented 7 years ago

How can I use this? I'm receiving: The option "types_options" does not exist.

plfort commented 7 years ago

Hello @murilolobato , this PR dates from July 2016 and the last relase is from June 2016, you may use "dev-master" as version for this package in composer to use this feature.

merk commented 7 years ago

I've just tagged 1.0.8