Problem/Motivation
Since #3277784: copyRawVariables should support default route parameters menu active trail information is missing from menu items under certain circumstances. In my case I've got a view with a path and menu entry and the rendered menu item no longer sets in_active_trail to TRUE when accessing the view on a page with the menu.
This issue is broken out from a different regression: #3358402: [regression] route defaults are now automatically route parameters. There a few relevant comments there:
I think that
$this->routeMatech->getRawParameters()->all()
returns a different set of key-value pairs which in turn leads to an empty result from$this->menuLinkManager->loadLinksByroute()
in MenuActiveTrail::getActiveLink():public function getActiveLink($menu_name = NULL) { [...] $route_parameters = $this->routeMatch->getRawParameters()->all(); // Load links matching this route. $links = $this->menuLinkManager->loadLinksByRoute($route_name, $route_parameters, $menu_name); // Select the first matching link. if ($links) { $found = reset($links); } [...] }
I have some routes that share the same Controller and Action, but in the route declaration it declares default parameters. For example I have the route
mymodule.news_list
(/news) which have the controllerListPageController::entryPoint
with a default parameter called type with value news-list. Then I have another route calledmymodule.articles_list
(/articles) which shares the same controller, but the default parameter type with value articles-list.Before when I was calling
\Drupal::service('plugin.manager.menu.link')->loadLinksByRoute('news_list')
, without any second second parameter (route params), it was returning me the menu links, but with the change in 9.5.9, I'm enforced to call\Drupal::service('plugin.manager.menu.link')->loadLinksByRoute('news_list', ['type' => 'news-list')
.For me this broke many small things, like breadcrumbs, custom menu blocks, etc.
Steps to reproduce
- Log in as admin.
- Navigate to
/admin/structure/views/add
. - Add a view with options:
- View name: Site content
- Create a page: checked
- Create a menu link: checked
- Menu: Main navigation
- Navigate to
/site-content
. - Inspect "Site content" main navigation item with browser tools and confirm class
primary-nav__menu-link--active-trail
is not present ona
element. - Revert changes from #3277784: copyRawVariables should support default route parameters (or just comment out
core/lib/Drupal/Core/Routing/Enhancer/ParamConversionEnhancer.php#L71-75
). - Rebuild caches.
- Navigate to
/site-content
. - Inspect "Site content" main navigation item with browser tools and confirm class
primary-nav__menu-link--active-trail
is present ona
element.
Proposed resolution
In MenuTreeStorage::loadByRoute()
also query without any default route parameters as they may not be present in the computed route_param_key.
Remaining tasks
Address @todo in MenuAccessTest::testSystemAdminMenuBlockAccessCheck()
referencing this issue.