The menu link of the default language is overwritten if you add/edit a translation.

Steps to reproduce:

  1. Install and enable token module
  2. Enable the translation for a content type
  3. Enable translation for menu links
  4. Set German as default language
  5. Create a node in French and on the node creation form, click "Provide a menu link" and add a menu link
  6. Translate this node and translate the menu link

The menu link of the default language, German, will be overwritten by the changes made to the menu link on the French translation. It also happens with English as the default language.

If you change the menu link of the default language, German, back to what it was before, the menu link on the French translation will not be changed. But if you edit the French translation and save the changes, the menu link of the French translation will overwrite the German menu link.

In order to fix above issue:

1. Uninstall token module
2. Currently, exploring other ways to fix this problem

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

criscom created an issue. See original summary.

Gábor Hojtsy’s picture

How would token module affect this and why?

Gábor Hojtsy’s picture

Title: Multilingual content: Menu link of default language overwritten by translations » Menu link of default language overwritten by translations if token module installed
Berdir’s picture

I guess this was introduced by #2670120: Patterns with node:menu-link tokens don't work on first node save. Pinged @larowlan.

criscom’s picture

Any progress on this?

Bambell’s picture

Here's a work in progress patch with a failing test exposing the bug. I think it's close, but not quite yet. I'll work a bit more on this today and will continue tomorrow if no one else picked this up and if it isn't solved yet.

Status: Needs review » Needs work

The last submitted patch, 6: menu_link_of_default-2769705-6.patch, failed testing.

The last submitted patch, 6: menu_link_of_default-2769705-6.patch, failed testing.

Bambell’s picture

Wanted to just add a translation to the MenuLinkContent, but here we go, that should work.

Bambell’s picture

Status: Needs review » Needs work

Should rather check if the active langcode of the loaded MenuLinkContent is the same as the one of the Node. If not, create a new one instead. Returns to Needs work, will fix shortly.

Bambell’s picture

Multilingual menu-link token replacement seems broken as well (as shown by this test failing).

Status: Needs review » Needs work

The last submitted patch, 11: menu_link_of_default-2769705-11.patch, failed testing.

The last submitted patch, 11: menu_link_of_default-2769705-11.patch, failed testing.

Bambell’s picture

So here we go with this, now adding a translation for the menu link. Nota bene the @todo.

Berdir’s picture

Status: Needs review » Needs work
+++ b/token.module
@@ -709,6 +709,14 @@ function token_node_menu_link_submit($entity_type, NodeInterface $node, &$form,
+        // If the loaded MenuLinkContent doesn't have a translation for the
+        // Node's active langcode, create a new translation.
+        $node_active_langcode = $node->language()->getId();
+        if (!$entity->hasTranslation($node_active_langcode)) {
+          $entity->addTranslation($node_active_langcode);
+          $entity->save();
+          $entity = \Drupal::service('entity.repository')->getTranslationFromContext($entity, $node_active_langcode);
+        }

Lets do this like _menu_ui_node_save().

There is also the isTranslatable() check. did you already create a core issue about it not working as expected when translation is disabled?

As discussed, we should at least add a (All languages) suffix on the ui if translation is disabled or have some other hint..

larowlan’s picture

Thanks @Bambell, didn't get to this on Friday

Bambell’s picture

Here we go. Will open a Core issue for menu link translation / "(all languages)", as discussed.

Bambell’s picture

  • Berdir committed 2cc6086 on 8.x-1.x authored by Bambell
    Issue #2769705 by Bambell: Menu link of default language overwritten by...
Berdir’s picture

Status: Needs review » Fixed

Thanks, pushed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.