$link->getPluginId() returns invalid value for loading menu_link_content entity

Created on 3 July 2025, 8 days ago

Problem/Motivation

On a Drupal 10.5.0 site, the translatable_menu_link_uri module attempts to load a menu_link_content entity using $link->getPluginId(), and passes it to entityTypeManager()->getStorage('menu_link_content')->load(). This returns null because:

  • getPluginId() returns a string like menu_link_content:UUID
  • load() expects a numeric entity ID, not a plugin ID or UUID

As a result, the entity fails to load properly, and translated menu links are not detected correctly.

Specifically, when a French version of a menu link is created, the frontend still displays the English version. This occurs because the module fails to load the translated entity, and it defaults to the original language instead of the expected translation.

Steps to reproduce

  1. Install and enable the translatable_menu_link_uri module on a Drupal 10.5.0 site
  2. Go to Structure » Menus and edit a menu (e.g., Main navigation)
  3. Add a custom menu link (e.g., title = “Test”, link = “internal:/node/1”)
  4. Enable translation for menu_link_content and its link field
  5. Translate the menu link into French from the UI
  6. Switch the site to the French language and view the page
  7. Observe that the menu still shows the English link, not the translated French one

Proposed resolution

Replace the incorrect entity loading logic:

// Before:
$entity = \Drupal::entityTypeManager()->getStorage('menu_link_content')->load($link->getPluginId());

// After:
$entity = $link->getEntity();

This ensures the plugin provides the correct entity instance, including proper translation context, without relying on broken UUID parsing.

Remaining tasks

  • Update the module to use $link->getEntity() instead of load(getPluginId())
  • Test with translated menu items and verify correct output per language
  • Attach patch or merge request (optional)
  • Code review and confirmation
🐛 Bug report
Status

Active

Version

2.1

Component

Code

Created by

🇨🇦Canada mfarhat

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

Comments & Activities

  • Issue created by @mfarhat
  • 🇨🇦Canada mfarhat

    This patch replaces `$link->getPluginId()` with `$link->getEntity()` to ensure proper entity loading in Drupal 10.5.0.

    It fixes the issue where translated menu links always fall back to the English version on multilingual sites.

    Steps to reproduce and resolution are fully documented in the summary above.

  • 🇨🇦Canada mfarhat

    Apologies — I initially opened this issue based on the behavior in the 2.1.1 release. After reviewing the `2.x` branch, I see that the problem has already been resolved there.

    No patch or merge request is needed.

    Thanks for maintaining the module

  • 🇨🇦Canada mfarhat

    mfarhat changed the visibility of the branch 3534085--fix-translated-link-entity-loading to hidden.

  • 🇨🇦Canada mfarhat

    Update: I originally opened this issue based on the 2.1.1 release, where the bug was still present.

    After reviewing the current `2.x` branch, I can confirm that the issue has already been fixed — the module now uses `$link->getEntity()` properly.

    No patch or merge request is needed. Apologies for the noise — and thank you for maintaining this module!

Production build 0.71.5 2024