Skip to content

Commit

Permalink
minor #3191 Make a better exception message (fabpot)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.0.x-dev branch.

Discussion
----------

Make a better exception message

Without this exception, PHP "crashes" as `null` is passed to `EasyCorp\Bundle\EasyAdminBundle\Router\CrudUrlBuilder::setController()`.

Commits
-------

56cee5c Make a better exception message
  • Loading branch information
javiereguiluz committed May 8, 2020
2 parents 6268d5b + 56cee5c commit e79af5c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Factory/MenuFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
use EasyCorp\Bundle\EasyAdminBundle\Config\UserMenu;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Menu\MenuItemInterface;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Dto\MainMenuDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\MenuItemDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\UserMenuDto;
Expand Down Expand Up @@ -121,7 +122,10 @@ private function generateMenuItemUrl(MenuItemDto $menuItemDto, string $dashboard
$entityFqcn = $routeParameters['entityFqcn'] ?? null;
if (null !== $entityFqcn && null === $urlBuilder->get('crudController')) {
$controllerRegistry = $this->adminContextProvider->getContext()->getCrudControllers();
$urlBuilder->setController($controllerRegistry->getControllerFqcnByEntityFqcn($entityFqcn));
if (null === $controllerFqcn = $controllerRegistry->getControllerFqcnByEntityFqcn($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);
}

if (null !== $urlBuilder->get('crudController')) {
Expand Down

0 comments on commit e79af5c

Please sign in to comment.