From: Jamie McClelland Date: Mon, 7 Jul 2014 20:35:39 +0000 (-0400) Subject: CRM-14955 - add custom tokens to greetings X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=ac21a108e699ed92c18f8cc6ee88dff1cc10c1ad;p=civicrm-core.git 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 --- 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); + } } }