Localize url in menu

Created on 5 June 2017, over 7 years ago
Updated 7 February 2023, over 1 year ago

Hi,

I'm loading a menu programmatically and building a renderable array then to display it.

Here's how:

    $menu_tree = \Drupal::menuTree();

    // Build the typical default set of menu tree parameters.
    $parameters = $menu_tree->getCurrentRouteMenuTreeParameters($menu_name);
    // Load the tree based on this set of parameters.
    $tree = $menu_tree->load($menu_name, $parameters);
    // Transform the tree using the manipulators you want.
    $manipulators = array(
      // Only show links that are accessible for the current user.
      array('callable' => 'menu.default_tree_manipulators:checkAccess'),
      // Use the default sorting of menu links.
      array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'),
    );
    $tree = $menu_tree->transform($tree, $manipulators);

    // Finally, build a renderable array from the transformed tree.
    return $menu_tree->build($tree);

The issue is that on a multilingual website, only the links title are being translated and not the url. The menu link content is well configured as I can have a different value for the url for each language.

A patch is coming up.

πŸ› Bug report
Status

Postponed: needs info

Version

10.1 ✨

Component
Menu link contentΒ  β†’

Last updated about 1 month ago

Created by

πŸ‡«πŸ‡·France garnett2125

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.

Production build 0.71.5 2024