-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
Milestone
Description
Describe the bug
After upgrade to v3.1.6, my AssociationField throw an exception. This seems to be caused by #3551
The error is still present in last release v3.2.7
To Reproduce
My Admin Controller:
class RestaurantCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return Restaurant::class;
}
public function configureActions(Actions $actions): Actions
{
return $actions
->add(Crud::PAGE_INDEX, Action::DETAIL);
}
public function configureFields(string $pageName): iterable
{
yield NumberField::new('id', 'id');
yield TextField::new('name', 'admin.restaurant.name.label');
yield AssociationField::new('address', 'admin.restaurant.address.label')
->setFormType(AddressFormType::class)
->renderAsNativeWidget()
;
yield EmailField::new('email', 'admin.restaurant.email.label');
yield TelephoneField::new('phone', 'admin.restaurant.phone.label')
->hideOnIndex();
yield BooleanField::new('open', 'admin.restaurant.open.label');
}
}My Entity Restaurant is really classic:
/**
* @ORM\Entity
* @ORM\Table(name="restaurant")
*/
class Restaurant
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
* @ORM\Column(type="string", length=255)
*/
protected $name;
/**
* @var Address
*
* @ORM\ManyToOne(targetEntity="Address", cascade={"persist"})
* @ORM\JoinColumn(name="address_id", referencedColumnName="id")
*/
protected $address;And my AddressFormType
class AddressFormType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('street', TextType::class, ['label' => 'admin.restaurant.address.street.label', 'required' => false])
->add('additional', TextType::class, ['label' => 'admin.restaurant.address.additional.label', 'required' => false])
->add('zipCode', TextType::class, ['label' => 'admin.restaurant.address.zip_code.label', 'required' => false])
->add('city', TextType::class, ['label' => 'admin.restaurant.address.city.label', 'required' => true])
->add('country', TextType::class, ['label' => 'admin.restaurant.address.country.label', 'required' => false])
;
}
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Address::class,
]);
}
}