EasyAdminBundle
EasyAdminBundle copied to clipboard
Menu item not highlighted with KnpPaginatorBundle default sort direction enabled
Describe the bug I don't really know if this is an EasyAdmin issue or a KnpPaginatorBundle issue. MenuItem is not highlighted when it links to a route where there is a paginator with default sort enable.
example :
in DashboardController.php
MenuItem::linkToRoute('Actualités', 'fa-solid fa-newspaper', 'newsletter'),
in NewsletterController.php
#[Route('/admin/newsletter', name: 'newsletter')]
public function index(Request $request): Response
{
$news = $this->newsRepository->findAll();
$news = $this->paginator->paginate(
$news ,
$request->query->getInt('page', 1),
20,
[
'defaultSortFieldName' => 'n.date',
'defaultSortDirection' => 'desc',
]
);
return $this->render('/newsletter/index.html.twig', [
'news ' => $news ,
]);
}
The item is not highlighted.
Inside the isSelected($menuItemDto) method inside the MenuItemMatcher.php :
$menuItemQueryParameters =
[
0 => "newsletter"
]
$currentPageQueryParameters =
[
0 => "desc"
1 => "newsletter"
]
Am I supposed to pass manually the default sort direction parameter into the MenuItem or is there another way ?
To Reproduce
"easycorp/easyadmin-bundle": "4.7.2",
"knplabs/knp-paginator-bundle": "6.2.0"
i recommend override standart MenuItemMatcher
### services.yaml
App\Components\Admin\Bundle\EasyAdminBundle\Menu\MenuItemMatcher:
decorates: EasyCorp\Bundle\EasyAdminBundle\Contracts\Menu\MenuItemMatcherInterface
class: App\Components\Admin\Bundle\EasyAdminBundle\Menu\MenuItemMatcher
arguments:
$adminContextProvider: '@EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider'
added in "inSelected" method one more condition
if (null !== $menuItemDto->getRouteName()) {
if ($menuItemDto->getRouteName() === $adminContext->getRequest()->query->get('routeName')) {
return true;
}
}