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
- Install Drupal,
- add second language and make content translatable,
- install module,
- disable "Show all enabled languages" selection in block configuration,
- make node, do not translate,
- 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;
}