From: Tim Otten Date: Mon, 6 Jul 2020 08:46:37 +0000 (-0700) Subject: Drupal.civi-setup.php - Don't assume that `$language` is available X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=aed5db5d86071243709b47bbca052cb1369c6e08;p=civicrm-core.git Drupal.civi-setup.php - Don't assume that `$language` is available --- diff --git a/setup/plugins/init/Drupal.civi-setup.php b/setup/plugins/init/Drupal.civi-setup.php index 75e7c5a3d4..b24d7c164c 100644 --- a/setup/plugins/init/Drupal.civi-setup.php +++ b/setup/plugins/init/Drupal.civi-setup.php @@ -59,7 +59,7 @@ if (!defined('CIVI_SETUP')) { // Compute default locale. global $language; - $model->lang = \Civi\Setup\LocaleUtil::pickClosest($language->langcode, $model->getField('lang', 'options')); + $model->lang = \Civi\Setup\LocaleUtil::pickClosest($language->langcode ?? NULL, $model->getField('lang', 'options')); }); function _drupal_civisetup_getPublicFiles() { diff --git a/setup/src/Setup/LocaleUtil.php b/setup/src/Setup/LocaleUtil.php index fe0c9f0e60..f996eb9a66 100644 --- a/setup/src/Setup/LocaleUtil.php +++ b/setup/src/Setup/LocaleUtil.php @@ -19,6 +19,10 @@ class LocaleUtil { * Ex: 'en_US'. */ public static function pickClosest($preferredLang, $availLangs, $default = 'en_US') { + if ($preferredLang === NULL || $preferredLang === '') { + return $default; + } + // Perhaps we have this exact language? if (isset($availLangs[$preferredLang])) { return $preferredLang;