I have many fields of type subclass of EntityType, something like this:
$builder->add('managers', SubclassEntityType::class, [
'class' => 'User',
'choice_label' => 'Managers',
'required' => false,
'query_builder' => function (UserRepository $er) {
return $er->getManagersQueryBuilder();
},
'multiple' => true,
]);
$builder->add('types', SubclassEntityType::class, [
'class' => 'Type',
'choice_label' => 'Types',
'required' => false,
'query_builder' => function (TypesRepository $er) {
return $er->getManagersQueryBuilder();
},
'multiple' => true,
]);
Could I dynamically add option (option of fields in select, not option of form) to all fields of the same type like this (Empty) => 'empty? I don't want to customize it for each field. I need this option to filter allow to add to field null values, for examples, find entities to which not manager is assigned. Would it be easier to solve this if it were subclass of ChoiceType?
I tried to subclass ChoiceType и add empty option in buildView, but in this case validation fails as well. Does anybody know how to add option and make validation work? It looks like adding option in buildView doesn't solve the problem.