CRM-13161, fixed token evaluation
authorkurund <kurund@civicrm.org>
Wed, 21 Aug 2013 14:11:08 +0000 (19:41 +0530)
committerkurund <kurund@civicrm.org>
Wed, 21 Aug 2013 14:11:08 +0000 (19:41 +0530)
----------------------------------------
* CRM-13161: Greetings are  not evaluated correctly if it includes prefix / suffix
  http://issues.civicrm.org/jira/browse/CRM-13161

CRM/Utils/Token.php

index 0e9981f882cb7e17ac640209c58358593c53ceba..28ca9417d3b32e21d01d27d8c9c8ac886cc503b3 100644 (file)
@@ -663,6 +663,11 @@ class CRM_Utils_Token {
     }
     else {
       $value = CRM_Utils_Array::retrieveValueRecursive($contact, $token);
+
+      // note that incase of pseudoconstants we get array ( 0 => id, 1 => label )
+      if (is_array($value)) {
+        $value = $value[1];
+      }
     }
 
     if (!$html) {
@@ -1185,6 +1190,10 @@ class CRM_Utils_Token {
     if (!empty($greetingTokens)) {
       // first use the existing contact object for token replacement
       if (!empty($contactDetails)) {
+        // unset id's to get labels for the pseudoconstants
+        foreach ( array('individual_prefix', 'individual_suffix', 'gender') as $field ) {
+          unset($contactDetails[0][$contactId][$field]);
+        }
         $tokenString = CRM_Utils_Token::replaceContactTokens($tokenString, $contactDetails, TRUE, $greetingTokens, TRUE);
       }