EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

CollectionField->useEntryCrudForm() on a CRUD without the configureFields() method does not work as expected

Open nevez opened this issue 2 years ago • 0 comments

Describe the bug I have a "TurnoCrudController" with this field configured in configureFields()

        `CollectionField::new('rigaTurnos')->useEntryCrudForm()->setEntryIsComplex()`

The "rigaTurnos" field is a OneToMany with "RigaTurno":

    #[ORM\OneToMany(mappedBy: 'turno', targetEntity: RigaTurno::class)]
    private Collection $rigaTurnos;

The RigaTurnoCrudController is this (the default created by make:admin:crud):

class RigaTurnoCrudController extends AbstractCrudController { public static function getEntityFqcn(): string { return RigaTurno::class; } }

As you can see, it has no configureFields() method, so the one defined in AbstractCrudController is used, that returns

$this->container->get(FieldProvider::class)->getDefaultFields($pageName);

The problem is that in FieldProvider->getDefaultFields() the entityDto is taken from the admin context:

$this->adminContextProvider->getContext()->getEntity();

...which obviously does NOT return RigaTurno, it returns Turno instead, which is the entity I am editing, which has the rigaTurnos CollectionField.

If you cannot/wont fix this issue, please at least mention in the documentation that using useEntryCrudForm() requires the configureFields() method to be defined in the associated CRUD.

EasyAdmin version: 4.8.5

Thank you

nevez avatar Nov 24 '23 17:11 nevez