Merge pull request #4493 from eileenmcnaughton/CRM-15555
[civicrm-core.git] / CRM / Utils / Token.php
index 12e21758e27056f244eb86d934f8d5b72117b5e7..dd81e288723afc3513440e0d6b94c18edf0920a2 100644 (file)
@@ -1364,12 +1364,14 @@ class CRM_Utils_Token {
           $escapeSmarty
         );
       }
+
       // check if there are still any unevaluated tokens
-      $greetingTokens = self::getTokens($tokenString);
+      $remainingTokens = self::getTokens($tokenString);
 
-      // $greetingTokens not empty, there are hook tokens to replace 
-      if (!empty($greetingTokens) ) {
+      // 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)) {
@@ -1720,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);
       }
     }