X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FUtils%2FToken.php;h=0e58f6e12dda537c21e573e3adcbd9fa682a9dd5;hb=bb239b22b7edcb2a585f4c2f3b41ec8d6b8c4181;hp=14de24649621f3a3ad8eb41b694c2cb93b3b97a3;hpb=cd061beab4edc81838d526d63d815d2d54320127;p=civicrm-core.git diff --git a/CRM/Utils/Token.php b/CRM/Utils/Token.php index 14de246496..0e58f6e12d 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,40 @@ 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); + } } } + /** + * @param $tokens + * + * @return array + */ static function flattenTokens(&$tokens) { $flattenTokens = array(); @@ -1680,7 +1720,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); } }