Invalid argument exception when changing language of node with menu link to und or zxx

Created on 27 August 2017, about 7 years ago
Updated 15 November 2023, about 1 year ago

Synopsis

Changing the language of a translatable node with a translatable menu link from a "real" language (e.g. en) to a "pseudo" language (und or zxx) will result in an invalid argument exception: or respectively.

Note: If you are using the contributed token module, you will get a similar error in token_node_menu_link_submit() instead, since that function uses code very similar to _menu_ui_node_save() (see related issues in the sidebar).

Steps to reproduce

  1. Install Drupal 10.1.x-dev (Standard profile) in English language
  2. Enable Content Translation module
  3. Add a second language (e.g. German) at Configuration > Region and language > Languages
  4. Enable content translation with default settings for Content/Basic page and Custom menu link/Custom menu link at Configuration > Region and language > Content language and translation
  5. Add a new basic page in English:
    1. Fill in the title field (e.g. "123")
    2. Expand "Menu settings" in the sidebar and check "Provide a menu link"
    3. Leave everything else at default settings
    4. Click "Save"
  6. Edit your new basic page:
    1. Set the language to either "- Not specified - " (und) or "- Not applicable -" (zxx)
    2. In "Menu settings" in the sidebar, change "Menu link title" to "234"
    3. Leave everything else alone
    4. Click "Save"

Expected result

  • Language of basic page is either und or zxx, depending on your choice above
  • Title of menu link is "234"
  • Language of menu link is equal to language of basic page
  • Neither basic page nor menu link have any translations

Actual result

White page with error message:

The website encountered an unexpected error. Please try again later.

InvalidArgumentException: Invalid translation language (und) specified. in Drupal\Core\Entity\ContentEntityBase->addTranslation() (line 952 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).

_menu_ui_node_save() (Line: 342)
menu_ui_form_node_form_submit()
call_user_func_array() (Line: 114)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers() (Line: 52)
Drupal\Core\Form\FormSubmitter->doSubmitForm() (Line: 597)
Drupal\Core\Form\FormBuilder->processForm() (Line: 325)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 73)
Drupal\Core\Controller\FormController->getContentResult()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 583)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 163)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 74)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 698)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Proposed resolution

The Menu UI module doesn't use the API correctly. It tries to add a translation when it shouldn't.

When updating a translatable menu link in _menu_ui_node_save() and the node is not translatable, don't try to add a translation for the untranslatable language, which would trigger the exception, but instead set the language of the menu link to the node language.

Remaining tasks

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

n/a

MR to commit

MR 5399

πŸ› Bug report
Status

Fixed

Version

10.2 ✨

Component
Menu UIΒ  β†’

Last updated 7 days ago

No maintainer
Created by

πŸ‡©πŸ‡ͺGermany FeyP

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