From 99e201e8cfe6da36d709566517b6ea57b8716592 Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Mon, 25 Feb 2019 11:36:02 +0000 Subject: [PATCH] Move assign of currency for entityForm outside of foreach so order of fields don't matter --- CRM/Core/Form/EntityFormTrait.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/CRM/Core/Form/EntityFormTrait.php b/CRM/Core/Form/EntityFormTrait.php index bc50635dec..63e5f781f9 100644 --- a/CRM/Core/Form/EntityFormTrait.php +++ b/CRM/Core/Form/EntityFormTrait.php @@ -162,7 +162,8 @@ trait CRM_Core_Form_EntityFormTrait { * Get the defaults for the entity. */ protected function getEntityDefaults() { - $defaults = []; + $defaults = $moneyFields = []; + if (!$this->isDeleteContext() && $this->getEntityId() ) { @@ -170,17 +171,23 @@ trait CRM_Core_Form_EntityFormTrait { $baoName = $this->_BAOName; $baoName::retrieve($params, $defaults); } - foreach ($this->entityFields as &$fieldSpec) { + foreach ($this->entityFields as $entityFieldName => $fieldSpec) { $value = CRM_Utils_Request::retrieveValue($fieldSpec['name'], $this->getValidationTypeForField($fieldSpec['name'])); if ($value !== FALSE && $value !== NULL) { $defaults[$fieldSpec['name']] = $value; } + // Store a list of fields with money formatters if (CRM_Utils_Array::value('formatter', $fieldSpec) == 'crmMoney') { - if (!empty($defaults['currency'])) { - $fieldSpec['formatterParam'] = $defaults['currency']; - } + $moneyFields[] = $entityFieldName; } } + if (!empty($defaults['currency'])) { + // If we have a money formatter we need to pass the specified currency or it will render as the default + foreach ($moneyFields as $entityFieldName) { + $this->entityFields[$entityFieldName]['formatterParam'] = $defaults['currency']; + } + } + // Assign again as we may have modified above $this->assign('entityFields', $this->entityFields); return $defaults; -- 2.25.1