Skip to content

Commit

Permalink
Add fix for enotice when trying to resolve custom data of type array
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Mar 16, 2021
1 parent 9f7f170 commit 5119782
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions CRM/Utils/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

}

0 comments on commit 5119782

Please sign in to comment.