Heitor
Heitor

Reputation: 111

Is there a way to set my form options app-wide in Symfony3?

For example, I want all my 'DateType' fields to be widget single_text with format dd/mm/yyyy. How to set those as the default options for my app?

Upvotes: 1

Views: 31

Answers (1)

Terenoth
Terenoth

Reputation: 2598

Create a BaseDateType class with the following content:

class BaseDateType extends AbstractType
{
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'widget' => 'single_text',
            'format' => 'dd/mm/yyyy',
        ]);
    }

    public function getParent()
    {
        return DateType::class;
    }
}

Then use BaseDateType in your forms, and you can still override options if you need.

Upvotes: 1

Related Questions