How to inherit FormType in Sonata Admin?
For example in src/AppBundle/Form/CityType.php:
class SmsType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name')
->add('recommend', ChoiceType::class, array(
'choices' => array(
'Maybe' => 0,
'Yes' => 1,
'No' => 2,
),
))
// ...
;
}
}
src/AppBundle/Admin/CityAdmin.php:
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('name')
->name('recommend')
// ...
;
}
And in my admin field recommend is text input instead of select.
I can:
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('name')
->name('recommend', ChoiceType::class, array(
'choices' => array(
'Maybe' => 0,
'Yes' => 1,
'No' => 2,
)
))
// ...
;
}
But then in two places I have the same code.
How is best way to refactor this?