From 21d40964c87507703faa23c3e74fb46d6c0277d2 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Thu, 11 Jul 2019 21:11:38 +0100 Subject: [PATCH] Add hook to alter display value or Custom field value --- CRM/Core/BAO/CustomField.php | 7 ++++++- CRM/Utils/Hook.php | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index bd50263945..05298e5e79 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -1067,7 +1067,12 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { $fieldInfo = ['options' => $field->getOptions()] + (array) $field; - return self::formatDisplayValue($value, $fieldInfo, $entityId); + $displayValue = self::formatDisplayValue($value, $fieldInfo, $entityId); + + // Call hook to alter display value. + CRM_Utils_Hook::alterCustomFieldDisplayValue($displayValue, $value, $entityId, $fieldInfo); + + return $displayValue; } /** diff --git a/CRM/Utils/Hook.php b/CRM/Utils/Hook.php index 00e217789c..0d09ab914b 100644 --- a/CRM/Utils/Hook.php +++ b/CRM/Utils/Hook.php @@ -2649,4 +2649,22 @@ abstract class CRM_Utils_Hook { ); } + /** + * This hook is called to alter Custom field value before its displayed. + * + * @param string $displayValue + * @param mixed $value + * @param int $entityId + * @param array $fieldInfo + * + * @return mixed + */ + public static function alterCustomFieldDisplayValue(&$displayValue, $value, $entityId, $fieldInfo) { + return self::singleton()->invoke( + ['displayValue', 'value', 'entityId', 'fieldInfo'], + $displayValue, $value, $entityId, $fieldInfo, self::$_nullObject, + self::$_nullObject, 'civicrm_alterCustomFieldDisplayValue' + ); + } + } -- 2.25.1