X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FUtils%2FToken.php;h=dd81e288723afc3513440e0d6b94c18edf0920a2;hb=e0c4f234b9eab061bade28bd91a39f8912f9e2be;hp=14de24649621f3a3ad8eb41b694c2cb93b3b97a3;hpb=dbc50e52b54307ad88595a46c61e19ee5e2809de;p=civicrm-core.git diff --git a/CRM/Utils/Token.php b/CRM/Utils/Token.php index 14de246496..dd81e28872 100644 --- a/CRM/Utils/Token.php +++ b/CRM/Utils/Token.php @@ -802,7 +802,16 @@ class CRM_Utils_Token { } return $tokenHtml; } - public static function getHookTokenReplacement( + + /** + * @param $token + * @param $contact + * @param $category + * @param bool $html + * @param bool $escapeSmarty + * + * @return mixed|string + */public static function getHookTokenReplacement( $token, &$contact, $category, @@ -1355,9 +1364,42 @@ class CRM_Utils_Token { $escapeSmarty ); } + + // check if there are still any unevaluated tokens + $remainingTokens = self::getTokens($tokenString); + + // contact related $greetingTokens not empty, there are customized or hook tokens to replace + if (!empty($remainingTokens['contact']) ) { + // Fill the return properties array + $greetingTokens = $remainingTokens['contact']; + 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); + } } } + /** + * @param $tokens + * + * @return array + */ static function flattenTokens(&$tokens) { $flattenTokens = array(); @@ -1680,7 +1722,12 @@ class CRM_Utils_Token { // Group by entity else { $split = explode('.', trim($k, '{}')); - $entity = isset($split[1]) ? ucfirst($split[0]) : 'Contact'; + if (isset($split[1])) { + $entity = array_key_exists($split[1], CRM_Core_DAO_Address::export()) ? 'Address' : ucfirst($split[0]); + } + else { + $entity = 'Contact'; + } $sorted[ts($entity)][] = array('id' => $k, 'text' => $v); } }