From 511978269308519939e4f4f5440f4cb3194f2722 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 15 Mar 2021 18:43:53 +1300 Subject: [PATCH] Add fix for enotice when trying to resolve custom data of type array --- CRM/Utils/Token.php | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/CRM/Utils/Token.php b/CRM/Utils/Token.php index e41a872038eb..442030ca7749 100644 --- a/CRM/Utils/Token.php +++ b/CRM/Utils/Token.php @@ -732,22 +732,12 @@ public static function getContactTokenReplacement( $value = "cs={$cs}"; } else { - $value = CRM_Utils_Array::retrieveValueRecursive($contact, $token); + $value = (array) CRM_Utils_Array::retrieveValueRecursive($contact, $token); - // FIXME: for some pseudoconstants we get array ( 0 => id, 1 => label ) - if (is_array($value)) { - $value = $value[1]; - } - // Convert pseudoconstants using metadata - elseif ($value && is_numeric($value)) { - $allFields = CRM_Contact_BAO_Contact::exportableFields('All'); - if (!empty($allFields[$token]['pseudoconstant'])) { - $value = CRM_Core_PseudoConstant::getLabel('CRM_Contact_BAO_Contact', $token, $value); - } - } - elseif ($value && CRM_Utils_String::endsWith($token, '_date')) { - $value = CRM_Utils_Date::customFormat($value); + foreach ($value as $index => $item) { + $value[$index] = self::convertPseudoConstantsUsingMetadata($value[$index], $token); } + $value = implode(', ', $value); } if (!$html) { @@ -1897,4 +1887,24 @@ public static function formatTokensForDisplay($tokens) { return $output; } + /** + * @param $value + * @param $token + * + * @return bool|int|mixed|string|null + */ + protected static function convertPseudoConstantsUsingMetadata($value, $token) { + // Convert pseudoconstants using metadata + if ($value && is_numeric($value)) { + $allFields = CRM_Contact_BAO_Contact::exportableFields('All'); + if (!empty($allFields[$token]['pseudoconstant'])) { + $value = CRM_Core_PseudoConstant::getLabel('CRM_Contact_BAO_Contact', $token, $value); + } + } + elseif ($value && CRM_Utils_String::endsWith($token, '_date')) { + $value = CRM_Utils_Date::customFormat($value); + } + return $value; + } + }