If there is no translation the switcher gives error

Created on 9 April 2024, 12 months ago

Problem/Motivation

When you have a page that does not have translation, an exception is thrown.

The website encountered an unexpected error. Try again later.

TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given in in_array() (line 153 of modules/contrib/lang_dropdown/src/Form/LanguageDropdownForm.php). 

Steps to reproduce

  1. Install Drupal,
  2. add second language and make content translatable,
  3. install module,
  4. disable "Show all enabled languages" selection in block configuration,
  5. make node, do not translate,
  6. use language dropdown to change language

Proposed resolution

      if (!$this->settings['showall'] && in_array('locale-untranslated', $lang_options['attributes']['class'], TRUE)) {
        continue;
      }

to

      if (!$this->settings['showall'] && !empty($lang_options['attributes']['class']) && in_array('locale-untranslated', $lang_options['attributes']['class'], TRUE)) {
        continue;
      }
      // Identify if session negotiation had set session-active class.
      if (in_array('session-active', $lang_options['attributes']['class'], TRUE)) {
        $language_session_selected = $lang_code;
      }

to

      // Identify if session negotiation had set session-active class.
      if (!empty($lang_options['attributes']['class']) && in_array('session-active', $lang_options['attributes']['class'], TRUE)) {
        $language_session_selected = $lang_code;
      }
🐛 Bug report
Status

Active

Version

2.1

Component

Code

Created by

🇫🇮Finland oakulm

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

Comments & Activities

  • Issue created by @oakulm
  • Status changed to Needs review 12 months ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.3 & MariaDB 10.3.22
    last update 12 months ago
    1 pass
  • Issue was unassigned.
  • Status changed to Needs work 28 days ago
  • 🇺🇸United States DamienMcKenna NH, USA

    Thank you for the bug report and the patches.

    Because Drupal has moved away from using patches to using merge requests, the latest patch will need to be turned into a merge request.

    Also, please remember to set the "assigned" field to "Unassigned" when you're finished working on an issue, that way others will know they can review it, continue working on it, etc.

Production build 0.71.5 2024