Problem/Motivation

Menu link URLs are not translatable. This is a problem regarding external URLs. Currently the only solution seems to be making a duplicate menu for the other language.

Proposed resolution

Make menu link URL translatable.

Issue fork drupal-2595839

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

juhog created an issue. See original summary.

juhog’s picture

Title: URL should be translatable » Menu link URL should be translatable
juhog’s picture

Makes the URL translatable pretty much the same way as title and description are translatable.

lauriii’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 3: menu-link-url-should-be-translatable-2595839-3.patch, failed testing.

dawehner’s picture

The problem is, its not that easy, when the URL is translatable, you also need multiple entries in the menu_tree table, you need to take care of multilingual etc. and boom it will get hard.

juhog’s picture

About menu_tree table:

I'm not sure how exactly this table is used, but isn't there a similiar problem about the title?

For example, if I create a menu link in English and then I translate it to Finnish, in menu_tree table I will have just one row and the title of that row is like this:

s:17:"Menu link finnish";

There's no trace of the English title in menu_tree table.

dawehner’s picture

No, its not. For static menu links we store the TranslatableString object.
For manually created menu links we have some logic on render time for that: \Drupal\menu_link_content\Plugin\Menu\MenuLinkContent::getTitle

The problem though is that in case your menu link URLs are translatable queries against the {menu_tree} table against the URL/route needs to behave differently. This is the main difference, you don't filter by the title.

Do you mind explain how general usecase, I think we should more try to solve that, I hope better hope in that.

lauriii’s picture

General usecase is when you try to link something to external service, you need to be able to set different URL for different languages because of the internal link generator is unable to create them.

dawehner’s picture

Okay well for external URLs it is easier indeed, maybe for those we could actually allow it when we have all the various validation in place.

dawehner’s picture

Version: 8.0.x-dev » 8.1.x-dev

This is certainly a feature request for 8.1.x now.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jsbalsera’s picture

Status: Needs work » Needs review
StatusFileSize
new2.14 KB
new3.74 KB

Hi everyone,

I have the need for this in one project, so I used the patch in #3, but also tried to add some validations to ensure that only external URLs can be translated. Then, when we add a translation and edit the original, I don't know what should happen if we try to change the link to internal, or if we try to add an internal link to the translation.

For this project it was enough to make the internal links always internal, and the externals also always externals, but I'm sure that's not the desired solution. Also, I'm not sure that I'm doing this in the right place. Anyway, I upload the patch in case someone can find it useful.

Status: Needs review » Needs work

The last submitted patch, 13: menu-link-url-should-be-translatable-2595839-13.patch, failed testing.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

ErnoVanhala’s picture

For me it was big surprise, that I cannot translate menu item urls. Now I need to build huge menus (including mainly external links) twice to get the wanted behaviour.

So +1 if someone creates solutions to this :)

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jlbellido’s picture

Status: Needs work » Needs review
StatusFileSize
new3.74 KB

Rerolled #13 to 8.4.x

Status: Needs review » Needs work

The last submitted patch, 18: menu_link_url_should_be-2595839-18.patch, failed testing.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

unrealauk’s picture

Status: Needs work » Needs review
StatusFileSize
new3.49 KB

I got the error with old links. I can't change internal URL to external URL its validation issue. So I removed this part from the patch.
Please review it.

Status: Needs review » Needs work

The last submitted patch, 22: menu_link_url_should_be-2595839-19.patch, failed testing. View results

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

hikkypo’s picture

I used patch 19 from #22 on drupal version 8.9.14

The patch almost works. After I save my menu item with an external link the text (all translations) will be removed from the url field and it will save the content separate from the original language. However I had the following issues with the current version of this patch.

1. This only worked on the translations but the original language kept being for all translations so changing and saving the original item would always overwrite all other languages.
2. You can technically now fill in an external url and then save the page. Then you can fill in an internal link and it will save the translation with this link.

So there should either be some ajax call which i think makes more sense because then you can swap between internal and external and/or on submit there should be a check to make sure the link being saved is still internal or external. And the original translation should be translatable. On top of that it needs to be updated for the newer drupal versions and tests need fixing.

seyfettinkahveci’s picture

StatusFileSize
new3.66 KB

Hi,

There was a multisite build for core 9.4. One of these installations was not multilingual. Patch #22 was giving the following error. I updated the patch as attached.

InvalidArgumentException: The URI '' is invalid. You must use a valid URI scheme.Array ( ) in Drupal\Core\Url::fromUri() (line 296 of /var/www/html/web/core/lib/Drupal/Core/Url.php).

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

akalam made their first commit to this issue’s fork.

akalam’s picture

Status: Needs work » Needs review
StatusFileSize
new3.7 KB

I've created a MR rerolling the patch from #33 to the latest Drupal 11.x release. I'm attaching also a static patch to apply safely from composer

smustgrave’s picture

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

Believe this feature will need test coverage.

Have not reviewed

gaurav_manerkar’s picture

Issue:
When link field is made untranslatable for a particular menu type from /admin/config/regional/content-language, I get the following error:

Error: Call to undefined method Drupal\Core\Field\Entity\BaseFieldOverride::setItemDefinition() in Drupal\menu_link_content\Entity\MenuLinkContent->setTranslationConstraints() (line 444 of /var/www/html/docroot/core/modules/menu_link_content/src/Entity/MenuLinkContent.php).

While debugging, i found that when link field is translatable, the $item_definition object is an instance of the class Drupal\Core\Field\BaseFieldDefinition and when it is non-translatable, the object is an instance of the class Drupal\Core\Field\Entity\BaseFieldOverride where the setItemDefinition method is not defined.

We should add an early return if the link field is non-translable in the field configuration.

gaurav_manerkar’s picture

StatusFileSize
new3.32 KB

Fix for issue described in #40

gilles_webstanz’s picture

I made a reroll patch for the drupal core version 11.2.0

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.