X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FUtils%2FMoney.php;h=786fccd64c0bbc4e4981a5bf3b9a48c30a09217e;hb=75e07da717507c673297dd5d2cda24208ab8155e;hp=c99a792167c766901f6d58c1cefdf53dfdf40f90;hpb=96879c169e7526004925e3eb6921ac03e7071985;p=civicrm-core.git diff --git a/CRM/Utils/Money.php b/CRM/Utils/Money.php index c99a792167..786fccd64c 100644 --- a/CRM/Utils/Money.php +++ b/CRM/Utils/Money.php @@ -67,14 +67,15 @@ class CRM_Utils_Money { } if (!empty($valueFormat) && $valueFormat !== '%!i') { - CRM_Core_Error::deprecatedFunctionWarning('Having a Money Value format other than !%i is deprecated, please report this on the GitLab Issue https://lab.civicrm.org/dev/core/-/issues/1494 with the relevant moneyValueFormat you use.'); + CRM_Core_Error::deprecatedWarning('Having a Money Value format other than %!i is deprecated, please report this on the GitLab Issue https://lab.civicrm.org/dev/core/-/issues/1494 with the relevant moneyValueFormat you use.'); + } + + if (!$currency) { + $currency = $config->defaultCurrency; } if ($onlyNumber) { - // money_format() exists only in certain PHP install (CRM-650) - if (is_numeric($amount) and function_exists('money_format')) { - $amount = money_format($valueFormat, $amount); - } + $amount = self::formatLocaleNumericRoundedByCurrency($amount, $currency); return $amount; } @@ -85,16 +86,16 @@ class CRM_Utils_Money { ]); } - if (!$currency) { - $currency = $config->defaultCurrency; - } - // ensure $currency is a valid currency code // for backwards-compatibility, also accept one space instead of a currency if ($currency != ' ' && !array_key_exists($currency, self::$_currencySymbols)) { throw new CRM_Core_Exception("Invalid currency \"{$currency}\""); } + if ($currency === ' ') { + CRM_Core_Error::deprecatedWarning('Passing empty currency to CRM_Utils_Money::format is deprecated if you need it for display without currency call CRM_Utils_Money::formatLocaleNumericRounded'); + } + $amount = self::formatNumericByFormat($amount, $valueFormat); // If it contains tags, means that HTML was passed and the // amount is already converted properly, @@ -181,7 +182,7 @@ class CRM_Utils_Money { */ protected static function formatLocaleNumeric($amount) { if (CRM_Core_Config::singleton()->moneyvalueformat !== '%!i') { - CRM_Core_Error::deprecatedFunctionWarning('Having a Money Value format other than !%i is deprecated, please report this on GitLab with the relevant moneyValueFormat you use.'); + CRM_Core_Error::deprecatedWarning('Having a Money Value format other than !%i is deprecated, please report this on GitLab with the relevant moneyValueFormat you use.'); } return self::formatNumericByFormat($amount, CRM_Core_Config::singleton()->moneyvalueformat); }