If there is no translation the switcher gives error

Created on 9 April 2024, 7 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

Needs review

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

Production build 0.71.5 2024