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.
| Comment | File | Size | Author |
|---|---|---|---|
| core-menu-link-translatable-d11.patch | 933 bytes | burcu.sogut@drupart.com.tr |
Issue fork drupal-3625171
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
Comment #2
larowlanNice find - any chance you could make an MR for this?
Comment #4
burcu.sogut@drupart.com.tr commentedThanks @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.
Comment #5
smustgrave commentedMoving 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.