How can I set a default choice on Symfony's EntityType, to use when the bound form object does not have a value?
I've tried the following (suggested in this answer), but the data
option overwrites even a bound value.
class FooEntityType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver)
{
...
$resolver->setDefaults([
'choices' => $fooEntities,
'class' => 'FooBundle:FooEntity',
'choice_label' => 'name',
'expanded' => true,
'multiple' => false,
'data' => $fooEntities[0],
]);
}
public function getParent()
{
return EntityType::class;
}
}