Skip to content
Snippets Groups Projects
Commit 92efe9ba authored by mattwire's avatar mattwire
Browse files

Update getDefaultCurrencyForForm() to use standard form functions where available

parent 09bd07be
No related branches found
No related tags found
No related merge requests found
......@@ -196,25 +196,14 @@ trait CRM_Core_Payment_MJWTrait {
*
* @return string
*/
public function getDefaultCurrencyForForm($form) {
// For contribution pages it is in $form->_values
$currency = $form->_values['currency'] ?? NULL;
// If we AJAX load and have more than one processor (eg. stripe, pay later) we can end up with the wrong
// currency set in $form->_values. So we use $form->getVar('currency') to get the right one!
if (!$currency && is_a($form, 'CRM_Financial_Form_Payment')) {
$currency = $form->getVar('currency');
}
// Due to https://github.com/civicrm/civicrm-core/pull/21966 currency might be set to the string "undefined"
if (!$currency || $currency === 'undefined') {
// For event pages it is in $form->_values['event']
if (isset($form->_values['event'])) {
$currency = $form->_values['event']['currency'] ?? NULL;
}
public function getDefaultCurrencyForForm($form): string {
if (method_exists($form, 'getCurrency')) {
$currency = $form->getCurrency();
}
if (!$currency || $currency === 'undefined') {
if (empty($currency) || $currency === 'undefined') {
// If we can't find it we'll use the default from the configuration
$currency = CRM_Core_Config::singleton()->defaultCurrency;
$currency = Civi::settings()->get('defaultCurrency');
}
return $currency;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment