How to re-use forms with some fields left out in Symfony2 How to re-use forms with some fields left out in Symfony2 symfony symfony

How to re-use forms with some fields left out in Symfony2


I think the best solution is to create a base abstract Type and let your Types extend it. Here's a short example:

namespace Acme\Bundle\DemoBundle\Form\Type;use Symfony\Component\Form\AbstractType;abstract FooBaseType extends AbstractType{    public function buildForm(FormBuilder $builder, array $options)    {        // Add all fields common for your other types.    }}

Now you can just extend it an include the missing fields

namespace Acme\Bundle\DemoBundle\Form\Type;class ExampleType extends FooBaseType{    public function buildForm(FormBuilder $builder, array $options)    {        parent::buildForm($builder, $options);        // Your missing fields    }}


see this github pull request: https://github.com/symfony/symfony-docs/pull/765

it seems to be exactly what you are looking for.