Problem/Motivation

On a multilingual site, a menu link created by the Menu link content module (MenuLinkContent plugin) can have its "link" field translated per language, so the target URL/path may differ between translations of the same menu link entity.

MenuLinkContent::getUrlObject() currently falls through to the parent implementation, which does not take the current language context into account when resolving the URL. As a result, the menu link renders with the URL from the entity's default/original translation instead of the URL stored in the active language's translation of the "link" field.

Proposed resolution

Override getUrlObject() in MenuLinkContent so that, when the site is multilingual, the URL is resolved from the current translation of the entity's "link" field (via getEntity()->get('link')->first()->getUrl()) instead of relying on the parent's non-translation-aware logic. On a non-multilingual site, behavior is unchanged (falls back to parent::getUrlObject()).

Remaining tasks

Review, add test coverage for the multilingual case.

Issue fork drupal-3625171

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

larowlan’s picture

Nice find - any chance you could make an MR for this?

burcu.sogut@drupart.com.tr’s picture

Status: Active » Needs review
Issue tags: +Needs tests

Thanks @larowlan. Opened MR !17352 from the patch.

Compared to the original patch, the MR now keeps the $title_attribute behaviour from MenuLinkBase::getUrlObject() (the description is still added as the title attribute), and it uses the entity's own getUrlObject() on the translation for the current language context. That is the same approach getTitle() and getDescription() already use. Non-multilingual sites keep the existing behaviour.

Tagging "Needs tests": this still needs a test for the multilingual case, a translated menu link whose link field differs per language.

smustgrave’s picture

Status: Needs review » Needs work

Moving to NW for the test coverage

Also the MR description read like AI per https://www.drupal.org/docs/develop/issues/issue-procedures-and-etiquett... all descriptions and summaries need to be written by the user please.

Thanks.