Load menu links for multiple routes

Created on 9 May 2025, 6 days ago

Problem/Motivation

This is a follow-up issue to πŸ› Class active-trail not added to li element when linking to front page Needs work .

Fixing the other issue introduced a performance penalty for the front page because an extra query had to be run in the menu system to check for link items matching <front>. This could be avoided if we had the ability to load menu links for multiple route names instead of just one at a time. Per @larowlan:

I don't think we can avoid the extra queries because we only have \Drupal\Core\Menu\MenuLinkManager::loadLinksByRoute and \Drupal\Core\Menu\MenuTreeStorageInterface::loadByRoute but I think it would be worth adding loadLinksByRoutes and loadByRoutes methods to both those services to support doing this in a single query.

@catch agreed that this task could be done in a follow-up issue.

Proposed resolution

  • Add \Drupal\Core\Menu\MenuLinkManager::loadLinksByRoutes.
  • Add \Drupal\Core\Menu\MenuTreeStorageInterface::loadByRoutes.
  • Update \Drupal\Core\Menu\MenuActiveTrail::getActiveLink() to use loadLinksByRoutes() for better performance.

Remaining tasks

User interface changes

Introduced terminology

API changes

Two new functions, one in MenuLinkManager and another in MenuTreeStorageInterface.

Data model changes

Release notes snippet

✨ Feature request
Status

Active

Version

11.0 πŸ”₯

Component

menu system

Created by

πŸ‡ΊπŸ‡ΈUnited States dcam

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @dcam
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    ,

  • Merge request !12086Added all proposed changes β†’ (Open) created by dcam
  • Pipeline finished with Failed
    6 days ago
    Total: 114s
    #492852
  • Pipeline finished with Failed
    6 days ago
    Total: 123s
    #492853
  • Pipeline finished with Failed
    6 days ago
    Total: 186s
    #492874
  • Pipeline finished with Failed
    6 days ago
    #492877
  • Pipeline finished with Failed
    6 days ago
    Total: 168s
    #492895
  • Pipeline finished with Failed
    6 days ago
    Total: 548s
    #492902
Production build 0.71.5 2024