From c3e97d121c35a0b9874728ff75a76d82721a11bc Mon Sep 17 00:00:00 2001 From: benjamin Date: Sun, 3 Dec 2023 16:10:40 +0000 Subject: [PATCH] dedicated function get l10n js asset build params --- CRM/Core/Resources.php | 23 +++++++++++++++++++++++ CRM/Core/Resources/Common.php | 13 +------------ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/CRM/Core/Resources.php b/CRM/Core/Resources.php index 748aaa1c26..a6c5f586e9 100644 --- a/CRM/Core/Resources.php +++ b/CRM/Core/Resources.php @@ -419,8 +419,31 @@ class CRM_Core_Resources implements CRM_Core_Resources_CollectionAdderInterface return $this->strings; } + /** + * Get the params used to render crm-l10n.js + * Gets called above the caching layer and then used + * in the render function below + */ + public static function getL10nJsParams(): array { + $settings = Civi::settings(); + return [ + 'cid' => CRM_Core_Session::getLoggedInContactID() ?: 0, + 'includeEmailInName' => (bool) $settings->get('includeEmailInName'), + 'ajaxPopupsEnabled' => (bool) $settings->get('ajaxPopupsEnabled'), + 'allowAlertAutodismissal' => (bool) $settings->get('allow_alert_autodismissal'), + 'resourceCacheCode' => Civi::resources()->getCacheCode(), + 'locale' => CRM_Core_I18n::getLocale(), + 'lcMessages' => $settings->get('lcMessages'), + 'dateInputFormat' => $settings->get('dateInputFormat'), + 'timeInputFormat' => $settings->get('timeInputFormat'), + 'moneyFormat' => CRM_Utils_Money::format(1234.56), + ]; + } + /** * Create dynamic script for localizing js widgets. + * Params come from the function above + * @see getL10nJsParams */ public static function renderL10nJs(GenericHookEvent $e) { if ($e->asset !== 'crm-l10n.js') { diff --git a/CRM/Core/Resources/Common.php b/CRM/Core/Resources/Common.php index e470406ace..73a8bd2b99 100644 --- a/CRM/Core/Resources/Common.php +++ b/CRM/Core/Resources/Common.php @@ -206,18 +206,7 @@ class CRM_Core_Resources_Common { // Dynamic localization script if (!CRM_Core_Config::isUpgradeMode()) { - $items[] = Civi::service('asset_builder')->getUrl('crm-l10n.js', [ - 'cid' => $contactID, - 'includeEmailInName' => (bool) $settings->get('includeEmailInName'), - 'ajaxPopupsEnabled' => (bool) $settings->get('ajaxPopupsEnabled'), - 'allowAlertAutodismissal' => (bool) $settings->get('allow_alert_autodismissal'), - 'resourceCacheCode' => Civi::resources()->getCacheCode(), - 'locale' => CRM_Core_I18n::getLocale(), - 'lcMessages' => $settings->get('lcMessages'), - 'dateInputFormat' => $settings->get('dateInputFormat'), - 'timeInputFormat' => $settings->get('timeInputFormat'), - 'moneyFormat' => CRM_Utils_Money::format(1234.56), - ]); + $items[] = Civi::service('asset_builder')->getUrl('crm-l10n.js', CRM_Core_Resources::getL10nJsParams()); } // These scripts are only needed by back-office users -- 2.25.1