Allow other modules to alter the active link trail

Created on 31 October 2016, about 8 years ago
Updated 4 October 2023, about 1 year ago

There is currently no way for other modules to alter the active link trail.

By adding a \Drupal::moduleHandler()->alter() call within getActiveTrailLink(), modules can choose to implement their own logic to complement the menu_trail_by_path implementation.

The attached patch attempts to do that. I don't know whether this is the best approach, but it seems to work on our current project. Comments/feedback welcome.

Feature request
Status

Needs work

Version

2.0

Component

Code

Created by

🇬🇧United Kingdom nicrodgers Monmouthshire, UK

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇩🇪Germany rauch

    Here is a patch for current module version 2.x

  • Status changed to RTBC about 1 year ago
  • 🇯🇵Japan moreaniket47@gmail.com Tokyo

    Having this feature definitely helps on top of the awesome work that this module does.
    Tested patch in #9 and works as expected. Marking as RTBC.

    fwiw, my use case was to parse menu items having links to view pages with contextual filters in the url path and add them to active trail - which became easy thanks to the hook!

  • Status changed to Needs work about 1 year ago
  • 🇨🇭Switzerland berdir Switzerland

    Seems like the alter hook should maybe pass all possible patches so a module could pick one of those?

    Also the service should gracefully handle when the injected service is not present, with an optional constructor argument and fall back to \Drupal::service() or people will have a fatal error that they might struggle to resolve.

Production build 0.71.5 2024