Skip to content

Commit

Permalink
Merge pull request #19692 from demeritcowboy/case-custom-money-5.35
Browse files Browse the repository at this point in the history
dev/core#2394 - Don't crash when saving custom case fields of type money
  • Loading branch information
seamuslee001 authored Mar 1, 2021
2 parents 7937515 + 3ec58ef commit c7f7155
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions CRM/Case/Form/CustomData.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,26 @@ public function formatCustomDataChangesForDetail($params) {
if (!empty($customFieldId) && is_numeric($customFieldId)) {
// Got a custom field ID
$label = civicrm_api3('CustomField', 'getvalue', ['id' => $customFieldId, 'return' => 'label']);
$oldValue = civicrm_api3('CustomValue', 'getdisplayvalue', [
'custom_field_id' => $customFieldId,
'entity_id' => $this->_entityID,
'custom_field_value' => $this->_defaults[$customField],
]);
$oldValue = $oldValue['values'][$customFieldId]['display'];
$newValue = civicrm_api3('CustomValue', 'getdisplayvalue', [
'custom_field_id' => $customFieldId,
'entity_id' => $this->_entityID,
'custom_field_value' => $newCustomValue,
]);
$newValue = $newValue['values'][$customFieldId]['display'];

// Convert dropdown and other machine values to human labels.
// Money is special for non-US locales because at this point it's in human format so we don't
// want to try to convert it.
$oldValue = $this->_defaults[$customField] ?? '';
$newValue = $newCustomValue;
if ('Money' !== civicrm_api3('CustomField', 'getvalue', ['id' => $customFieldId, 'return' => 'data_type'])) {
$oldValue = civicrm_api3('CustomValue', 'getdisplayvalue', [
'custom_field_id' => $customFieldId,
'entity_id' => $this->_entityID,
'custom_field_value' => $oldValue,
]);
$oldValue = $oldValue['values'][$customFieldId]['display'];
$newValue = civicrm_api3('CustomValue', 'getdisplayvalue', [
'custom_field_id' => $customFieldId,
'entity_id' => $this->_entityID,
'custom_field_value' => $newCustomValue,
]);
$newValue = $newValue['values'][$customFieldId]['display'];
}
$formattedDetails[] = $label . ': ' . $oldValue . ' => ' . $newValue;
}

Expand Down

0 comments on commit c7f7155

Please sign in to comment.