Describe the bug
I add a setController to MenuItem but it dosn't add the crudControllerFqcn= to the link.
So i add it manuel to the url in browser
&crudControllerFqcn=App\Controller\Admin\AdminUserCrudController
and its work correct
To Reproduce
yield MenuItem::linkToCrud('Benutzer', 'fa fa-user', User::class)
->setController(AdminUserCrudController::class);
(OPTIONAL) Additional context
Symfony 5.1
We changed this a few days ago. URLs no longer contain a crudControllerFqcn parameter but a crudId value that refers to some CRUD FQCN. It's explained here: https://github.com/EasyCorp/EasyAdminBundle/pull/3260
Even if you don't have that crudControllerFqcn query param, everything should keep working the same. Did you experience any issue?
I think a problem setController don't work now. I have split my Backend in two pieces one for {Route}/admin and one for {Route}/user.
I have two controller to handle it. For this two member areas
AdminDashboardController.php and UserDashboardController.php .
I handle the entity files with different crudController example for user: UserCrudController.php
example for admin: AdminUserCrudController.php
Before i updates the bundle its work correct with setController.
The Repro is on github:
https://github.com/rogergerecke/alt-sym/blob/master/src/Controller/Admin/AdminDashboardController.php#L76
or i misunderstood how you plan the integration of it???
I can't reproduce this 馃槓 Please, update to the latest dev-master version to see if it was fixed by a bug fix that we merged related to dashboard routes.
If this doesn't fix, please try to find the cause of this bug so we can fix it. Thanks.
Don't work i search for the cause but in moment i dosnt found the logic bug.
But the &crudId=71ae784 is every time the same so it use every time the same controller UserCrudController::class
And dosnt the set one
dont work
yield MenuItem::linkToCrud('Benutzer', 'fa fa-user', User::class)
->setQueryParameter('crudControllerFqcn',AdminUserCrudController::class);
dont work
yield MenuItem::linkToCrud('Benutzer', 'fa fa-user', User::class)
->setController(AdminUserCrudController::class);
@rogergerecke your comment gave me the clue I needed. Now I see the error and also why I couldn't reproduce it. I'll work on a fix. Thanks!
I was wrong ... I can't reproduce it :(
yield MenuItem::linkToCrud(..., ..., Entity::class)yield MenuItem::linkToCrud(..., ..., Entity::class)->setController(TheOtherCrudController::class)This works as expected: the first one links to one crud controller and the other one links to the explicit controller configured.
We'll need to investigate your issue deeper.
yea thats right logic but in my aplication dosnt work it i dont now wy.
I have test
/**
* @Route("/admin", name="admin")
*/
public function index(): Response
{
$routeBuilder = $this->get(CrudUrlGenerator::class)->build();
$this->user_route = $routeBuilder->setController(AdminUserCrudController::class)->generateUrl();
return parent::index();
}
After this $this->user_route contain the right crudId
http://localhost/admin?crudAction=index&crudId=20def93
Manuel open this uri in Browser works and the right CrudController is load.
But
yield MenuItem::linkToCrud('Benutzer', 'fa fa-user', User::class)
->setController(AdminUserCrudController::class);
This dont work create link with the same crudid
http://localhost/admin?crudAction=index&crudId=71ae784
This dont work parameter are empty (this function only for outgoing links?)
yield MenuItem::linkToUrl('Benutzer', 'fa fa-user', $this->user_route)
I think the problem begin here
https://github.com/EasyCorp/EasyAdminBundle/blob/37d4d5c7640472a0e93d388a4dee2e5250d3e8e0/src/Factory/MenuFactory.php#L139
entityFqcn is every time no zero?
this help me when add this
// 1. if entityFqcn is defined, find the crudFqcn from it...
if (null !== $entityFqcn) {
$crudControllers = $this->adminContextProvider->getContext()->getCrudControllers();
if (null === $controllerFqcn = $crudControllers->findCrudFqcnByEntityFqcn($entityFqcn)) {
throw new \RuntimeException(sprintf('Unable to find the controller related to the "%s" Entity; did you forget to extend "%s"?', $entityFqcn, AbstractCrudController::class));
}
if (null !== $crudControllerFqcn){
$urlBuilder->setController($crudControllerFqcn);
}else
{
$urlBuilder->setController($controllerFqcn);
}
$urlBuilder->unset('entityFqcn');
Or change first if crudControllerFqcn is it zero other wise check entityFqcn
Look at the lines 139 - 157
Fixes #3300
Solution:
So it is correct, the order of the question must change. entityFqcn otherwise always no zero
EasyAdminBundle/src/Factory/MenuFactory.php change the lines 136 - 159 to the code at the bottom then its working corect.
$entityFqcn = $routeParameters['entityFqcn'] ?? null;
$crudControllerFqcn = $routeParameters['crudControllerFqcn'] ?? null;
// 1. if crudControllerFqcn is defined, find the crudFqcn from it...
if (null !== $crudControllerFqcn) {
if (null === $crudControllerFqcn) {
throw new \RuntimeException(sprintf('The CRUD menu item with label "%s" must define either the entity FQCN (using the third constructor argument) or the CRUD Controller FQCN (using the "setController()" method).', $menuItemDto->getLabel()));
}
$urlBuilder->setController($crudControllerFqcn);
// 2. ...otherwise, use the entityFqcn
} else {
$crudControllers = $this->adminContextProvider->getContext()->getCrudControllers();
if (null === $controllerFqcn = $crudControllers->findCrudFqcnByEntityFqcn($entityFqcn)) {
throw new \RuntimeException(sprintf('Unable to find the controller related to the "%s" Entity; did you forget to extend "%s"?', $entityFqcn, AbstractCrudController::class));
}
$urlBuilder->setController($controllerFqcn);
$urlBuilder->unset('entityFqcn');
}
return $urlBuilder->generateUrl();
}
@javiereguiluz solution see above. :-)
Pull solution see above.