CRM-14955 - add custom tokens to greetings
authorJamie McClelland <jm@mayfirst.org>
Mon, 7 Jul 2014 20:35:39 +0000 (16:35 -0400)
committerJamie McClelland <jm@mayfirst.org>
Mon, 7 Jul 2014 20:35:39 +0000 (16:35 -0400)
----------------------------------------
* CRM-14955: can't add custom defined tokens to custom greetings
  https://issues.civicrm.org/jira/browse/CRM-14955

CRM/Utils/Token.php

index bd5b16598a9155d17b8a8467afd5ef595b7ab7bc..12e21758e27056f244eb86d934f8d5b72117b5e7 100644 (file)
@@ -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);
+      }
     }
   }