sonata-project / SonataAdminBundle

The missing Symfony Admin Generator
https://docs.sonata-project.org/projects/SonataAdminBundle
MIT License
2.11k stars 1.26k forks source link

Create constants for field options #7919

Closed dmitryuk closed 2 years ago

dmitryuk commented 2 years ago

Form types has a lot of options (required, help, field_type, label, ...), which not set as constants, but strings. So any developer should remember these, do typos and so on. I think it will better to create storage for constants For example as a result,

$filter->add(
                'account',
                null,
                [SonataAdmin::SHOW_FILTER => true, SonataAdmin::FIELD_TYPE => ChoiceType::class],
                [SonataAdmin::CHOICES     => $this->accounts]
            )

What do you think? What class to use for purpose?

VincentLanglet commented 2 years ago

In your example show_filter and field_type are sonata options but choices is a symfony option.

For FieldDescription, there is a lot of different types and each has his own constantes, that would make not sens to add them generically here.

For filters, we might introduce constants in https://github.com/sonata-project/SonataAdminBundle/blob/4.x/src/Filter/Filter.php and custom options in each filters https://github.com/sonata-project/SonataDoctrineORMAdminBundle/blob/4.x/src/Filter/StringFilter.php#L120-L123

but it would be weird having constants for some options (like filters) and not others.

Symfony doesn't use constant for options key, and it's worked for years without any issues https://symfony.com/doc/current/reference/forms/types/choice.html#field-options So I don't think it will be really useful