Merge pull request #22808 from colemanw/searchKitMailingTask
[civicrm-core.git] / Civi / Core / Format.php
index 57bdea8c542148d1e93b087c67f6e1b42880a999..b3076d0e8dc6b6f314c941c47729ec54e4480fc0 100644 (file)
@@ -30,6 +30,8 @@ class Format {
    *
    * @return string
    *
+   * @throws \CRM_Core_Exception
+   *
    * @noinspection PhpDocMissingThrowsInspection
    * @noinspection PhpUnhandledExceptionInspection
    */
@@ -41,7 +43,7 @@ class Format {
       $currency = Civi::settings()->get('defaultCurrency');
     }
     if (!isset($locale)) {
-      $locale = CRM_Core_I18n::getLocale();
+      $locale = Civi::settings()->get('format_locale') ?? CRM_Core_I18n::getLocale();
     }
     $money = Money::of($amount, $currency, NULL, RoundingMode::HALF_UP);
     $formatter = $this->getMoneyFormatter($currency, $locale);
@@ -61,6 +63,7 @@ class Format {
    *   add any padding.
    *
    * @return string
+   * @throws \CRM_Core_Exception
    */
   public function number($amount, ?string $locale = NULL, array $attributes = [
     NumberFormatter::MIN_FRACTION_DIGITS => 0,
@@ -147,7 +150,7 @@ class Format {
    * we are looking at how to manage an 'opt in'
    */
   protected function isUseSeparatorSettings(): bool {
-    return !CRM_Utils_Constant::value('IGNORE_SEPARATOR_CONFIG');
+    return !Civi::settings()->get('format_locale') && !CRM_Utils_Constant::value('IGNORE_SEPARATOR_CONFIG');
   }
 
   /**
@@ -214,7 +217,7 @@ class Format {
     }
     // Verify the amount is a number or numeric string/object.
     // We cast to string because it can be a BigDecimal object.
-    elseif ($amount === TRUE || !is_numeric((string) $amount)) {
+    if ($amount === TRUE || !is_numeric((string) $amount)) {
       throw new \CRM_Core_Exception('Invalid value for type money');
     }
     return (string) $amount;