When I'm using a choice_value function in order to exclude some data in my select, if the field is empty, a value is set to database but not "NULL". this value is the first entry of my entity. When I list all data, if the field is empty, "Null" value is set in database.
Any ideas ?
public function buildForm(FormBuilderInterface $builder, array $options)
{
$this->currentId = $options['currentId'];
$builder
->add('oldOwners', entityType::class, array(
'class' => OldOwners::class,
'required' => false,
'empty_data' => null,
'multiple' => false,
'choice_value' => function (OldOwners $oldOwners = null) {
if ($oldOwners != null && $oldOwners != '') {
if ($this->currentId != 0 && $oldOwners->animal->getId() == $this->currentId)
return $oldOwners->getDateDisposal()->format('Y-m-d');
}
},
'choice_label' => function (OldOwners $oldOwners = null) {
if ($oldOwners != null && $oldOwners != '') {
if ($this->currentId != 0 && $oldOwners->animal->getId() == $this->currentId)
return $oldOwners->getDateDisposal()->format('Y-m-d');
}
},
'label' => "Date"));
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Adopting::class,
'currentId' => null,
]);
$resolver->setRequired('currentId');
}