EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

feat: highlight menu item on custom routes

Open pfpro opened this issue 1 year ago • 2 comments

EasyAdmin: 4.11.1

Since the sidebar menu is now working again for normal use cases after the last EasyAdmin update, I would like to point out two problems with custom routes:

1 For the entity COMPANY, for example, I use my own DETAIL action in my own custom controller.

/admin?routeName=backend_crm_company_show&routeParams%5BentityId%5D=1

When I open this route, my parent menu entry (CRM) is neither expanded nor is the actual COMPANY menu entry highlighted.

In this case, is it necessary for me to manually open/highlight a menu entry? How would that work now? Or is there another approach?

2

/admin?routeName=backend_finance_dashboard
/admin?routeName=backend_finance_dashboard&year=2024&month=09

In the former case, the menu opens correctly and an entry is highlighted - in the latter case, it does not.

Any help would be appreciated.

pfpro avatar Aug 07 '24 08:08 pfpro

+1

kov-lucas avatar Aug 07 '24 09:08 kov-lucas

One of my actions is a link to a different Symfony Controller, so the menu item is also not expandend/selected. If you inject the AdminContextProvider in that Controller you can manipulate the menuItem. Something like this:

        $context = $this->adminContextProvider->getContext();
        $menuItems = $context->getMainMenu()->getItems();
        foreach ($menuItems as $menuItem) {
            if ($menuItem .... ) {
                $menuItem->setExpanded(true);
                foreach ($menuItem->getSubItems() as $subItem) {
                if(...) {
                    $subItem->setSelected(true);
                }

bt-nn avatar Aug 07 '24 11:08 bt-nn