Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New logic of Menu item matcher displays as selected all same crud controller in Sub Menus #6521

Open
AmazingBeu opened this issue Nov 7, 2024 · 1 comment
Labels

Comments

@AmazingBeu
Copy link

Describe the bug

with the new logic of Menu item matcher introduced in ee2c0ae, all SubMenu Items with the same Crud are selected, instead of the specific selected:
image

Comment out this function fix the behavior:

$menuItemController = $menuItemQueryParameters[EA::CRUD_CONTROLLER_FQCN] ?? null;
$currentPageController = $currentPageQueryParameters[EA::CRUD_CONTROLLER_FQCN] ?? null;
$actionsLinkedInTheMenuForThisEntity = $controllersAndActionsLinkedInTheMenu[$currentPageController] ?? [];
$menuOnlyLinksToIndexActionOfThisEntity = $actionsLinkedInTheMenuForThisEntity === [Crud::PAGE_INDEX];
if ($menuItemController === $currentPageController && $menuOnlyLinksToIndexActionOfThisEntity) {
$menuItemDto->setSelected(true);
break;
}

a possible workaround is to add a second MenuItem of the same Crud in the same SubMenu like this:

yield MenuItem::linkToCrud('', '', Team::class)->setHtmlAttribute("hidden", "1")

It break my usage of parent -> child entities:
image

To Reproduce

class DashboardController extends AbstractDashboardController
{
    public function configureMenuItems(): iterable
    {
        yield MenuItem::subMenu('subMenu 1')->setSubItems([
            MenuItem::linkToCrud('subItem 1', '', User::class)->setQueryParameter("ParentId", 1)          
        ]);
        yield MenuItem::subMenu('subMenu 2')->setSubItems([
            MenuItem::linkToCrud('subItem 2', '', User::class)->setQueryParameter("ParentId", 2)          
        ]);
    }
}

then click on one of the SubItem

@madflow
Copy link

madflow commented Nov 21, 2024

So ... we are having the same issue, migrating from a 3.x codebase.

Thank you for the hint using the yield MenuItem::linkToCrud('', '', Team::class)->setHtmlAttribute("hidden", "1") hack :) .

I wonder how a feasible permanent fix would look like. The comment above before the code block in question

// if the menu only contains links to the INDEX action of the CRUD controller,
sort of states, that this is "wanted" behaviour. I did not come with an idea how to fix this without breaking previous behaviour. Maybe it is an easy fix for EA veterans.

Would it maybe be feasible to make the MenuItemMatcher extensible via composition, plugins, ... ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants