dedicated function get l10n js asset build params
authorbenjamin <benjamin>
Sun, 3 Dec 2023 16:10:40 +0000 (16:10 +0000)
committerbenjamin <benjamin>
Sun, 3 Dec 2023 16:45:33 +0000 (16:45 +0000)
CRM/Core/Resources.php
CRM/Core/Resources/Common.php

index 748aaa1c2629519233b74eba92c6a7bf973ef9dc..a6c5f586e9210c111a91849cda7898a053b3102a 100644 (file)
@@ -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') {
index e470406ace9122affa42c14d28b48a73619dd6c0..73a8bd2b991d2c15a90ff903ca26d2e755bb717d 100644 (file)
@@ -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