From aed5db5d86071243709b47bbca052cb1369c6e08 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 6 Jul 2020 01:46:37 -0700 Subject: [PATCH] Drupal.civi-setup.php - Don't assume that `$language` is available --- setup/plugins/init/Drupal.civi-setup.php | 2 +- setup/src/Setup/LocaleUtil.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) 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; -- 2.25.1