EasyCorp / EasyAdminBundle

EasyAdmin is a fast, beautiful and modern admin generator for Symfony applications.
MIT License
4.08k stars 1.02k forks source link

[CrudUrlBuilder] Transform crudControllerFqcn into crudId fail to generate url after redirect #4116

Closed cristobal85 closed 2 years ago

cristobal85 commented 3 years ago

When transform 'crudControllerFqcn' into 'crudId', there are fails on associationfield links and actions link after redirect to URL generated by CrudUrlGenerator.

The "App\Entity\Requester\UserRequest" entity with "id = 46" does not exist in the database. The entity may have been deleted by mistake or by a "cascade={"remove"}" operation executed by Doctrine.

However, the link is an AssociationField to App\Entity\Requester\Request, no App\Entity\Requester\UserRequest. The UserRequest Entity is the current entity (UserRequest has one Request).

The links generated are:

Current URL: /admin/requester?crudAction=index& crudControllerFqcn=App%5CController%5CBackend%5CRequester%5CUserRequestCrudController& menuIndex=2& signature=-HCz9mpXuN7krlQPJuFrOtnGNNuOUkJUabgvuGWnLho&submenuIndex=-1

AssociationField URL: /admin/requester? crudAction=detail& crudControllerFqcn=App%5CController%5CBackend%5CRequester%5CRequestCrudController& entityId=46& referrer=%2Fadmin%2Frequester%3FcrudAction%3Dindex%26crudControllerFqcn%3DApp%255CController%255CBackend%255CRequester%255CUserRequestCrudController%26menuIndex%3D2%26signature%3D-HCz9mpXuN7krlQPJuFrOtnGNNuOUkJUabgvuGWnLho%26submenuIndex%3D-1& signature=s9WceVxIiH9bKq1A_Ls6lhcIZv4dqZPZuh-f3M0jfcg

Current URL: admin/requester? crudAction=index& crudId=a22e04b& entityId=13& menuIndex=2& signature=yrRyZQ1wT_OoVJReVIbQd65GYt-kANIfOGDwpsNc2Dk

AssociationField URL: /admin/requester? crudAction=detail& crudControllerFqcn=App%5CController%5CBackend%5CRequester%5CUserRequestCrudController& entityId=46& referrer=%2Fadmin%2Frequester%3FcrudAction%3Dindex%26crudId%3Da22e04b%26entityId%3D13%26menuIndex%3D2%26signature%3DyrRyZQ1wT_OoVJReVIbQd65GYt-kANIfOGDwpsNc2Dk& signature=YUmbljefwTLOLsuxLPYsTc1bu3WchB9dleNqYl2ji3U

Current URL: /admin/requester? crudAction=index& crudControllerFqcn=App%5CController%5CBackend%5CRequester%5CUserRequestCrudController&dashboardControllerFqcn=App%5CController%5CBackend%5CRequester%5CRequesterDashboardController& entityId=13& menuIndex=2& signature=g8DN-BrJhWMwhqyF4YipJjWdI0dudiwnE8zU4lVw3jI

AssociationField URL: /admin/requester? crudAction=detail& crudControllerFqcn=App%5CController%5CBackend%5CRequester%5CRequestCrudController& entityId=46&referrer=%2Fadmin%2Frequester%3FcrudAction%3Dindex%26crudControllerFqcn%3DApp%255CController%255CBackend%255CRequester%255CUserRequestCrudController%26entityId%3D13%26menuIndex%3D2%26signature%3Dg8DN-BrJhWMwhqyF4YipJjWdI0dudiwnE8zU4lVw3jI& signature=s9WceVxIiH9bKq1A_Ls6lhcIZv4dqZPZuh-f3M0jfcg

Enviroment:

michael-roth commented 3 years ago

We have the same problem with our edit action links with EasyAdmin 3.2.7.

I think this can be fixed by adding the crudId param to $requestParameters in ActionFactory::generateActionUrl()?

https://github.com/EasyCorp/EasyAdminBundle/blob/3a4c9bc2991dd1f94acce13c790dfc4063930cc2/src/Factory/ActionFactory.php#L152

$requestParameters = [
    EA::CRUD_CONTROLLER_FQCN => $request->query->get(EA::CRUD_CONTROLLER_FQCN),
    EA::CRUD_ID => $request->query->get(EA::CRUD_ID), // <-- add this line
    EA::CRUD_ACTION => $actionDto->getCrudActionName(),
    EA::REFERRER => $this->generateReferrerUrl($request, $actionDto, $currentAction),
];
treenoder commented 3 years ago

Same problem with EasyAdmin 3.2.7. After clicking on default edit link from an index action.

treenoder commented 3 years ago

Strangely, it works with Country entity, but not working with Price entity.

treenoder commented 3 years ago

So, for future readers. The problem was mistyped repository class name in the entity class.

javiereguiluz commented 2 years ago

I'm closing this old issue because CrudUrlBuilder is no longer used in the project and we've switched to an AdminUrlGenerator class. Hopefully this problem doesn't happen in the new URL builder. Cheers!

m-schmale commented 2 years ago

I had the same error message today. I generated two urls and for second url I forgot that the entity id of the first url was still in place. Maybe this helps someone with the same stupid mistake. 😆