Skip to content

Commit

Permalink
Merge pull request #13696 from mattwire/entityform_13578_fix
Browse files Browse the repository at this point in the history
Move assign of currency for entityForm outside of foreach so order of fields don't matter
  • Loading branch information
eileenmcnaughton authored Feb 26, 2019
2 parents 57b70ca + 99e201e commit 7de88d7
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions CRM/Core/Form/EntityFormTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,25 +162,32 @@ protected function addFormButtons() {
* Get the defaults for the entity.
*/
protected function getEntityDefaults() {
$defaults = [];
$defaults = $moneyFields = [];

if (!$this->isDeleteContext() &&
$this->getEntityId()
) {
$params = ['id' => $this->getEntityId()];
$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;
Expand Down

0 comments on commit 7de88d7

Please sign in to comment.