Consolidate getCurrency()
authorEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 23 Nov 2023 22:00:43 +0000 (11:00 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 28 Nov 2023 20:26:41 +0000 (09:26 +1300)
CRM/Contribute/Form/AbstractEditPayment.php
CRM/Contribute/Form/Contribution.php
CRM/Contribute/Form/ContributionBase.php
CRM/Core/Form.php
CRM/Event/Form/Registration.php
CRM/Financial/Form/Payment.php

index 408a4b7a563638faced5dee3391929679f722298..aff8f72a668ce48a66731ec12c5d4e6e73383272 100644 (file)
@@ -404,19 +404,6 @@ class CRM_Contribute_Form_AbstractEditPayment extends CRM_Contact_Form_Task {
     $this->assign_by_ref('paymentProcessor', $this->_paymentProcessor);
   }
 
-
-  /**
-   * Get the currency in use.
-   *
-   * This just defaults to getting the default currency
-   * where the form does not have better currency support.
-   *
-   * @return string
-   */
-  public function getCurrency(): string {
-    return (string) \Civi::settings()->get('defaultCurrency');
-  }
-
   /**
    * @param array $submittedValues
    *
index 8db797ae7b63458ff63e0b0fe9a2af03b4e5af1b..f37dc232d268d1c289d134223687683688fbddb7 100644 (file)
@@ -555,15 +555,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
     return $defaults;
   }
 
-  /**
-   * Get submitted currency, or use default.
-   *
-   * @return string
-   */
-  public function getCurrency(): string {
-    return (string) $this->getSubmittedValue('currency') ?: CRM_Core_Config::singleton()->defaultCurrency;
-  }
-
   /**
    * Build the form object.
    *
index ac4e5d27d7c92d1d77f10f39182997a4a4da200f..c40d24d7a37b5a7f19b4fe70137d71d4a0357190 100644 (file)
@@ -1502,4 +1502,25 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
     }
   }
 
+  /**
+   * Get the currency for the form.
+   *
+   * Rather historic - might have unneeded stuff
+   *
+   * @return string
+   */
+  public function getCurrency() {
+    $currency = $this->_values['currency'] ?? NULL;
+    // 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 (string) $currency;
+  }
+
 }
index 539f85b6e048a26a5c7265c4742cab03240b244e..461a0c32752150e090e8d95d03496987a54eba9c 100644 (file)
@@ -2933,24 +2933,17 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
   /**
    * 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.
-   *
    * @return string
    */
   public function getCurrency() {
-    $currency = $this->_values['currency'] ?? NULL;
-    // 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 ($this->getSubmittedValue('currency')) {
+      return $this->getSubmittedValue('currency');
     }
-    if (empty($currency)) {
-      $currency = CRM_Utils_Request::retrieveValue('currency', 'String');
+    $currency = CRM_Utils_Request::retrieveValue('currency', 'String');
+    if ($currency) {
+      return $currency;
     }
-    // @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;
+    return \Civi::settings()->get('defaultCurrency');
   }
 
   /**
index 1c7a8fd96c3f2443b8f4e6a626d314cdcb2f2c7f..de3baa8de7d9bc269d2c368641f177dfe1120d05 100644 (file)
@@ -1727,4 +1727,25 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
     return $this->getPriceSetID() && CRM_Price_BAO_PriceSet::isQuickConfig($this->getPriceSetID());
   }
 
+  /**
+   * Get the currency for the form.
+   *
+   * Rather historic - might have unneeded stuff
+   *
+   * @return string
+   */
+  public function getCurrency() {
+    $currency = $this->_values['currency'] ?? NULL;
+    // 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 e1937e149b364f1190e4f931f2ff3adf1da5ee5b..f52d2cad70e3c44f558c686fc469e3c54bc0d65a 100644 (file)
@@ -69,13 +69,10 @@ class CRM_Financial_Form_Payment extends CRM_Core_Form {
   /**
    * Get currency
    *
-   * @param array $submittedValues
-   *   Required for consistency with other form methods.
-   *
    * @return string
    */
-  public function getCurrency($submittedValues = []) {
-    return $this->currency;
+  public function getCurrency(): string {
+    return (string) $this->currency;
   }
 
   /**