+ /**
+ * Format the custom data changes as [label]: [old value] => [new value]
+ *
+ * @param array $params New custom field values from form
+ *
+ * @return string
+ * @throws \CiviCRM_API3_Exception
+ */
+ public function formatCustomDataChangesForDetail($params) {
+ $formattedDetails = [];
+ foreach ($params as $customField => $newCustomValue) {
+ if (substr($customField, 0, 7) == 'custom_') {
+ if ($this->_defaults[$customField] == $newCustomValue) {
+ // Don't show values that did not change
+ continue;
+ }
+ // We need custom field ID from custom_XX_1
+ list($_, $customFieldId, $_) = explode('_', $customField);
+
+ 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'];
+ $formattedDetails[] = $label . ': ' . $oldValue . ' => ' . $newValue;
+ }
+
+ }
+ }
+
+ return implode('<br/>', $formattedDetails);
+ }
+