Repository: EasyCorp/EasyAdminBundle (language: php)

Issue:
Regression: menu items are not highlighted on action pages
**Describe the bug**
The v4.5.0 introduced a regression via https://github.com/EasyCorp/EasyAdminBundle/commit/1f2cb5d0f2bcfa0a4a0d0b1dfe38be7b2ff8850a. Previously menu items were highlighted automatically when navigating to an action (e.g. Add). Now the highlight is gone.

**Additional context**
List view on v4.4.5 and v4.5.0 looks the same:
<img width="1218" alt="image" src="https://user-images.githubusercontent.com/1227834/209253167-4de0ad96-6ee2-4ecf-8b0d-b9c202dbaa16.png">

Built-in add action on v4.4.5:
<img width="1218" alt="image" src="https://user-images.githubusercontent.com/1227834/209253340-03cd8832-f5bb-4b2f-b026-e5b3fcf84ee6.png">

Built-in add action on v4.5.0, notice lack of highlight in the menu:
<img width="1218" alt="image" src="https://user-images.githubusercontent.com/1227834/209253228-94bc9abe-41fe-4008-9594-65296dc9cdea.png">



Discussion / hints:
I can confirm this issue (easycorp/easyadmin-bundle, v4.5.0).
And I can confirmed on the mentioned version. for custom submenu is also not clear how to highlight right now. 
Same problem with submenus. Once you enter edit/detail the submenu gets collapsed.
As mentioned in #5628 I think that the new behavior is the expected one.

Creating a product is not the same as listing all the products. that's why we shouldn't highlight the same menu item when different actions happen.

But, I'll keep this issue open so I can read more opinions from you. Thanks.
@javiereguiluz In my opinion, creating/editing/showing a page should also be highlighted, because highlighted should be to the entity, not just to the listing


 
I agree with @Glancu here. After update of our test environment I've got 3 reports from users that the UI "is broken". Programming-wise it makes sense to not highlight them, but UX-wise it is logical for users they creating/editing/custom entity actions are a part of that workflow.
Maybe set a configuration on the MenuItem (isEntityMenu) ?
If isEntityMenu, index/new/edit highlight the menu.

We could create this menu:

```
Customers->isEntityMenu(true)
Products
  Create->isEntityMenu(false)
  Listing->isEntityMenu(false)
```


Fix patch:
diff --git a/src/Menu/MenuItemMatcher.php b/src/Menu/MenuItemMatcher.php
index 9c38b56f37..2cd081375a 100644
--- a/src/Menu/MenuItemMatcher.php
+++ b/src/Menu/MenuItemMatcher.php
@@ -2,6 +2,7 @@
 
 namespace EasyCorp\Bundle\EasyAdminBundle\Menu;
 
+use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
 use EasyCorp\Bundle\EasyAdminBundle\Config\Option\EA;
 use EasyCorp\Bundle\EasyAdminBundle\Dto\MenuItemDto;
 use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
@@ -33,8 +34,9 @@ public function isSelected(MenuItemDto $menuItemDto): bool
             return $menuItemDto->getLinkUrl() === $adminContext->getRequest()->getUri();
         }
 
-        $menuItemQueryParameters = $this->filterIrrelevantQueryParameters($menuItemQueryParameters);
-        $currentPageQueryParameters = $this->filterIrrelevantQueryParameters($currentPageQueryParameters);
+        $menuItemLinksToIndexCrudAction = Crud::PAGE_INDEX === ($menuItemQueryParameters[EA::CRUD_ACTION] ?? false);
+        $menuItemQueryParameters = $this->filterIrrelevantQueryParameters($menuItemQueryParameters, $menuItemLinksToIndexCrudAction);
+        $currentPageQueryParameters = $this->filterIrrelevantQueryParameters($currentPageQueryParameters, $menuItemLinksToIndexCrudAction);
 
         // needed so you can pass route parameters in any order
         sort($menuItemQueryParameters);
@@ -63,10 +65,20 @@ public function isExpanded(MenuItemDto $menuItemDto): bool
      * should be ignored when deciding if some menu item matches the current page
      * (such as the applied filters or sorting, the listing page number, etc.).
      */
-    private function filterIrrelevantQueryParameters(array $queryStringParameters): array
+    private function filterIrrelevantQueryParameters(array $queryStringParameters, bool $menuItemLinksToIndexCrudAction): array
     {
         $paramsToRemove = [EA::REFERRER, EA::PAGE, EA::FILTERS, EA::SORT];
 
+        // if the menu item being inspected links to the 'index' action of some entity,
+        // remove both the CRUD action and the entity ID from the list of parameters;
+        // this way, an 'index' menu item is highlighted for all actions of the same entity;
+        // however, if the menu item points to an action different from 'index' (e.g. 'detail',
+        // 'new', or 'edit'), only highlight it when the current page points to that same action
+        if ($menuItemLinksToIndexCrudAction) {
+            $paramsToRemove[] = EA::CRUD_ACTION;
+            $paramsToRemove[] = EA::ENTITY_ID;
+        }
+
         return array_filter($queryStringParameters, static fn ($k) => !\in_array($k, $paramsToRemove, true), \ARRAY_FILTER_USE_KEY);
     }
 }


Test patch: