CRM-21482 improve handling for currency on form
authoreileen <emcnaughton@wikimedia.org>
Sun, 26 Nov 2017 23:10:46 +0000 (12:10 +1300)
committereileen <emcnaughton@wikimedia.org>
Sun, 26 Nov 2017 23:11:17 +0000 (12:11 +1300)
Change-Id: I63f3f5445b39b9bd6068835ae61c3e488177ce75

CRM/Core/Form.php
CRM/Core/Payment/ProcessorForm.php

index 6d772bb78cd31ed1c471df9c400dc4b5865fdb58..da2e0f38da89f7ecc3b9c9d89450012cb5d1172a 100644 (file)
@@ -2360,4 +2360,25 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
     return $name;
   }
 
+  /**
+   * Get the currency for the form.
+   *
+   * @todo this should be overriden on the forms rather than having this
+   * historic, possible handling in here. As we clean that up we should
+   * add deprecation notices into here.
+   */
+  public function getCurrency() {
+    $currency = CRM_Utils_Array::value('currency', $this->_values);
+    // For event forms, currency is in a different spot
+    if (empty($currency)) {
+      $currency = CRM_Utils_Array::value('currency', CRM_Utils_Array::value('event', $this->_values));
+    }
+    if (empty($currency)) {
+      $currency = CRM_Utils_Request::retrieveValue('currency', 'String');
+    }
+    // @todo If empty there is a problem - we should probably put in a deprecation notice
+    // to warn if that seems to be happening.
+    return $currency;
+  }
+
 }
index 720dae52253b2507f3488a91277fa1cf343183fa..81e0273c6f7dae62e38df3c2f3cd51926092ff64 100644 (file)
@@ -72,11 +72,7 @@ class CRM_Core_Payment_ProcessorForm {
 
     $form->assign('suppressSubmitButton', $form->_paymentObject->isSuppressSubmitButtons());
 
-    $currency = CRM_Utils_Array::value('currency', $form->_values);
-    // For event forms, currency is in a different spot
-    if (empty($currency)) {
-      $currency = CRM_Utils_Array::value('currency', $form->_values['event']);
-    }
+    $currency = $form->getCurrency();
     $form->assign('currency', $currency);
 
     // also set cancel subscription url