dev/core#2493 Add support for money fields to
authorEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 20 Sep 2021 21:44:27 +0000 (09:44 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 20 Sep 2021 21:44:27 +0000 (09:44 +1200)
This ensures that any money fields retrieved by  are
in a machine usable format.

We've been switching to this function rather than 'passing around arrays'
but we need to ensure this function is returning clean money to
prevent regressions.

CRM/Core/Form.php

index 69fc4ccb62bee3b83637c3651d8a1e1d771b8578..e139e04262dfafda8b067e5c4ae6608b959edf39 100644 (file)
@@ -70,6 +70,16 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    */
   public $_action;
 
+  /**
+   * Monetary fields that may be submitted.
+   *
+   * Any fields in this list will be converted to non-localised format
+   * if retrieved by `getSubmittedValue`
+   *
+   * @var array
+   */
+  protected $submittableMoneyFields = [];
+
   /**
    * Available payment processors.
    *
@@ -2746,7 +2756,11 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
     if (empty($this->exportedValues)) {
       $this->exportedValues = $this->controller->exportValues($this->_name);
     }
-    return $this->exportedValues[$fieldName] ?? NULL;
+    $value = $this->exportedValues[$fieldName] ?? NULL;
+    if (in_array($fieldName, $this->submittableMoneyFields, TRUE)) {
+      return CRM_Utils_Rule::cleanMoney($value);
+    }
+    return $value;
   }
 
   /**