From ac21a108e699ed92c18f8cc6ee88dff1cc10c1ad Mon Sep 17 00:00:00 2001 From: Jamie McClelland Date: Mon, 7 Jul 2014 16:35:39 -0400 Subject: [PATCH] CRM-14955 - add custom tokens to greetings ---------------------------------------- * CRM-14955: can't add custom defined tokens to custom greetings https://issues.civicrm.org/jira/browse/CRM-14955 --- CRM/Utils/Token.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/CRM/Utils/Token.php b/CRM/Utils/Token.php index bd5b16598a..12e21758e2 100644 --- a/CRM/Utils/Token.php +++ b/CRM/Utils/Token.php @@ -1364,6 +1364,32 @@ class CRM_Utils_Token { $escapeSmarty ); } + // check if there are still any unevaluated tokens + $greetingTokens = self::getTokens($tokenString); + + // $greetingTokens not empty, there are hook tokens to replace + if (!empty($greetingTokens) ) { + // Fill the return properties array + reset($greetingTokens); + $greetingsReturnProperties = array(); + while(list($key) = each($greetingTokens)) { + $props = array_flip(CRM_Utils_Array::value($key, $greetingTokens)); + $props = array_fill_keys(array_keys($props), 1); + $greetingsReturnProperties = $greetingsReturnProperties + $props; + } + $contactParams = array('contact_id' => $contactId); + $greetingDetails = self::getTokenDetails($contactParams, + $greetingsReturnProperties, + FALSE, FALSE, NULL, + $greetingTokens, + $className + ); + // Prepare variables for calling replaceHookTokens + $categories = array_keys($greetingTokens); + list($contact) = $greetingDetails; + // Replace tokens defined in Hooks. + $tokenString = CRM_Utils_Token::replaceHookTokens($tokenString, $contact[$contactId], $categories); + } } } -- 2.25.1