Closed
Description
Hi,
We are trying to replace a "entity" field by changing only options in an event subscriber.
So basically what we do is:
$form->add(
$field->getName(),
$field->getConfig()->getType()->getName(),
array_merge($field->getConfig()->getOptions(), array('disabled' => true))
);
The problem is that it seems the ->getOptions()
returns the normalized options and not the original ones. Thus the em
option is normalized and em
is not a string anymore but the concrete entity manager.
This is problematic because then the DoctrineType
throws an exception because it only deals with strings or null values:
// Symfony\Bridge\Doctrine\Form\Type\DoctrineType;
$emNormalizer = function (Options $options, $em) use ($registry) {
/* @var ManagerRegistry $registry */
if (null !== $em) {
return $registry->getManager($em); // This is where the exception is thrown
}
// ...
I think that the code below should probably fix the problem:
// Symfony\Bridge\Doctrine\Form\Type\DoctrineType;
$emNormalizer = function (Options $options, $em) use ($registry) {
/* @var ManagerRegistry $registry */
if (null !== $em) {
if (is_object($em)) {
return $em;
}
return $registry->getManager($em);
}
// ...
What is your opinion?