2020use EasyCorp \Bundle \EasyAdminBundle \Field \AssociationField ;
2121use EasyCorp \Bundle \EasyAdminBundle \Form \Type \CrudAutocompleteType ;
2222use EasyCorp \Bundle \EasyAdminBundle \Form \Type \CrudFormType ;
23+ use EasyCorp \Bundle \EasyAdminBundle \Orm \EntityRepository as EAEntityRepository ;
2324use EasyCorp \Bundle \EasyAdminBundle \Router \AdminUrlGeneratorInterface ;
2425use Symfony \Component \HttpFoundation \RequestStack ;
2526use Symfony \Component \PropertyAccess \Exception \UnexpectedTypeException ;
@@ -38,6 +39,7 @@ public function __construct(
3839 private RequestStack $ requestStack ,
3940 private ControllerFactory $ controllerFactory ,
4041 private FieldFactory $ fieldFactory ,
42+ private EAEntityRepository $ entityRepository ,
4143 ) {
4244 }
4345
@@ -49,14 +51,19 @@ public function supports(FieldDto $field, EntityDto $entityDto): bool
4951 public function configure (FieldDto $ field , EntityDto $ entityDto , AdminContext $ context ): void
5052 {
5153 $ propertyName = $ field ->getProperty ();
54+ $ resolvedProperty = $ this ->entityRepository ->resolveNestedAssociations (null , $ entityDto , $ propertyName , true );
55+ /** @var EntityDto $entityDtoResolved */
56+ $ entityDtoResolved = $ resolvedProperty ['entity_dto ' ];
57+ /** @var string $resolvedProperty */
58+ $ resolvedProperty = $ resolvedProperty ['property_name ' ];
5259
5360 if (!$ this ->isAssociation ($ entityDto ->getClassMetadata (), $ propertyName )) {
5461 throw new \RuntimeException (sprintf ('The "%s" field is not a Doctrine association, so it cannot be used as an association field. ' , $ propertyName ));
5562 }
5663
5764 // the target CRUD controller can be NULL; in that case, field value doesn't link to the related entity
5865 $ targetCrudControllerFqcn = $ field ->getCustomOption (AssociationField::OPTION_EMBEDDED_CRUD_FORM_CONTROLLER )
59- ?? $ context ->getAdminControllers ()->findCrudControllerByEntity ($ entityDto ->getClassMetadata ()->getAssociationTargetClass ($ propertyName ));
66+ ?? $ context ->getAdminControllers ()->findCrudControllerByEntity ($ entityDtoResolved ->getClassMetadata ()->getAssociationTargetClass ($ resolvedProperty ));
6067
6168 if (true === $ field ->getCustomOption (AssociationField::OPTION_RENDER_AS_EMBEDDED_FORM )) {
6269 if (false === $ entityDto ->getClassMetadata ()->isSingleValuedAssociation ($ propertyName )) {
0 commit comments