EasyCorp / EasyAdminBundle

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

feat: highlight menu item on custom routes #6403

Open pfpro opened 1 month ago

pfpro commented 1 month ago

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.

kov-lucas commented 1 month ago

+1

bt-nn commented 1 month ago

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);
                }