Check if Node have translation before getting it

Created on 18 September 2024, 2 months ago
Updated 20 September 2024, 2 months ago

Problem/Motivation

_menu_link_sync_get_link_for_target_language function do not check if the node have the translation before getting it.

This is a problem during the execution of โ€œ_menu_link_sync_get_most_popular_menu_among_siblingsโ€ where this function is used to find the most popular menu for the current language based on the source translation. The result is that the destination language is loaded even if it doesn't exist.

Steps to reproduce

- Create a node in one language, place it at the root of a menu.
- Create a other node in the same language, place it at the root of a menu.
- For the second node, create a translation in another language and sync the menu item.

The following error is displayed:

InvalidArgumentException: Invalid translation language (__TRANSLATION_LANGCODE_) specified. in Drupal\Core\Entity\ContentEntityBase->getTranslation() (line 903 of docroot/core/lib/Drupal/Core/Entity/ContentEntityBase.php).

Proposed resolution

Check if translation exists before loading it.

๐Ÿ› Bug report
Status

Active

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024