Answer the question
In order to leave comments, you need to log in
Write to DB values from EntityType in FormBuilder?
It's probably easier to show with code:
There is an entity User, it has a ManagerId, that is, an integer.
/** @ORM\Column(name="manager_id", type="integer", nullable=true) */
protected $managerId;
->add('managerId', EntityType::class, array(
'label' => 'Менеджер',
'class' => 'WPUserBundle:User',
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('u')
->setParameter('role', '%MANAGER%')
->where('u.roles LIKE :role');
},
'choice_label' => 'id',
'choice_value' => 'id',
'choice_name' => 'id',
'empty_data' => 1
))
Notice: Object of class WP\UserBundle\Entity\User could not be converted to double
Answer the question
In order to leave comments, you need to log in
Thanks to BoShurik for the tip.
Using the DataTransformer, it was not possible to solve the problem, for some reason it still did not transform the data. Therefore, I went on a crutch, made a SUBMIT event on the form and this code:
->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) {
$user = $event->getData();
$form = $event->getForm();
if (!$user) {
return;
}
$manager = $user->getManagerId();
if (!$manager) {
return;
}
$user->setManagerId($manager->getId());
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question