From 6aa4783c10ab398bd7914f5fd64482dd81094298 Mon Sep 17 00:00:00 2001 From: olayiwola-compucorp <85277674+olayiwola-compucorp@users.noreply.github.com> Date: Tue, 17 Oct 2023 06:20:29 +0100 Subject: [PATCH] BTHAB-207: Do not attempt to format custom value of empty string Included in - PR: https://github.com/civicrm/civicrm-core/pull/25451 --- CRM/Core/BAO/CustomField.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index fab2821bfe49..7c847941c261 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -1264,19 +1264,21 @@ private static function formatDisplayValue($value, $field, $entityId = NULL) { break; case 'Text': - if ($field['data_type'] == 'Money' && isset($value)) { + if ($field['data_type'] === 'Money' && isset($value)) { // $value can also be an array(while using IN operator from search builder or api). + $values = []; foreach ((array) $value as $val) { - $disp[] = CRM_Utils_Money::formatLocaleNumericRoundedForDefaultCurrency($val); + $values[] = $val === '' ? '' : CRM_Utils_Money::formatLocaleNumericRoundedForDefaultCurrency($val); } - $display = implode(', ', $disp); + $display = implode(', ', $values); } - elseif ($field['data_type'] == 'Float' && isset($value)) { + elseif ($field['data_type'] === 'Float' && isset($value)) { // $value can also be an array(while using IN operator from search builder or api). + $values = []; foreach ((array) $value as $val) { - $disp[] = CRM_Utils_Number::formatLocaleNumeric($val); + $values[] = $val === '' ? '' : CRM_Utils_Number::formatLocaleNumeric($val); } - $display = implode(', ', $disp); + $display = implode(', ', $values); } break; }