Strict language check or fallback to default language

Created on 23 December 2020, almost 4 years ago
Updated 24 March 2023, over 1 year ago

Problem/Motivation

Currently, a node that is not translatable will not be found when looking it up by machine name in getProtectedNodeByMachineName().

E.g. the site is multilingual but we provide a default fallback in EN only would result in null when trying to fetch the node on another translated page.

    $node = NULL;
    if (count($nodes)) {
      $node = reset($nodes);
      $lang_code = \Drupal::languageManager()->getCurrentLanguage()->getId();
      if ($node->hasTranslation($lang_code)) {
        $node = $node->getTranslation($lang_code);
      }
      else {
        $node = NULL;
      }
    }

Proposed resolution

Fallback to using the node in the default site language. Maybe make this option configurable.

πŸ“Œ Task
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium pjonckiere

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