Menu ui link defaults should be loaded from node language

Created on 4 September 2019, over 5 years ago
Updated 16 September 2024, 4 months ago

Problem/Motivation

I want to reuse menu_ui_get_menu_link_defaults() function. The problem is when trying to retrieve default values for a menu link the language is loaded from the context. It makes it impossible to use it with the node language you are passing to the function.

Assuming you want to display all menu link translations on one page for a specific node, all menu default values will come in the current language context whereas coming from the node languages you are passing to the function.

I don't know if there was any reason for that but I think that as the node is the parameter for this function this change is more flexible than getting current language from context.

Proposed resolution

Whereas fetching the menu translation from context:

$menu_link = MenuLinkContent::load($id);
$menu_link = \Drupal::service('entity.repository')->getTranslationFromContext($menu_link);

Load the menu translation from the node passed as argument to the function:

$menu_link = MenuLinkContent::load($id);
$menu_link = $menu_link->getTranslation($node->language()->getId());

Remaining tasks

none, patch attached.

πŸ“Œ Task
Status

Active

Version

11.0 πŸ”₯

Component
Menu systemΒ  β†’

Last updated 18 minutes ago

Created by

πŸ‡­πŸ‡·Croatia Aporie

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