From af25c7a505438e70a991da9c0f7ea042de5720e9 Mon Sep 17 00:00:00 2001 From: Adam Wood <72983627+webmaster-cses-org-uk@users.noreply.github.com> Date: Sun, 7 Nov 2021 13:09:31 +0000 Subject: [PATCH] Guard against passing empty values to CRM_Core_DAO::getFieldValue() This change removes a potential "getFieldValue failed" error that can be thrown if an empty scalar value occurs in a multiple-contact reference custom field. See https://lab.civicrm.org/dev/core/-/issues/2939 Replaces https://github.com/eileenmcnaughton/civicrm-core/pull/13/commits which was opened against the wrong repo. --- CRM/Core/BAO/CustomField.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index b7a92bae4c..984afff29a 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -1096,11 +1096,17 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { case 'Radio': case 'CheckBox': if ($field['data_type'] == 'ContactReference' && (is_array($value) || is_numeric($value))) { - $displayNames = []; - foreach ((array) $value as $contactId) { - $displayNames[] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactId, 'display_name'); + // Issue #2939 - guard against passing empty values to CRM_Core_DAO::getFieldValue(), which would throw an exception + if (empty($value)) { + $display = ''; + } + else { + $displayNames = []; + foreach ((array) $value as $contactId) { + $displayNames[] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactId, 'display_name'); + } + $display = implode(', ', $displayNames); } - $display = implode(', ', $displayNames); } elseif ($field['data_type'] == 'ContactReference') { $display = $value; -- 2.25.1