greeeting token and handle multi-value custom field fixes
authordeb.monish <monish.deb@webaccessglobal.com>
Fri, 13 Jan 2017 12:18:50 +0000 (17:48 +0530)
committerdeb.monish <monish.deb@webaccessglobal.com>
Fri, 13 Jan 2017 12:38:01 +0000 (18:08 +0530)
CRM/Activity/Tokens.php
CRM/Contribute/Tokens.php
CRM/Event/Tokens.php
CRM/Member/Tokens.php
Civi/Token/TokenCompatSubscriber.php
Civi/Token/TokenRow.php

index 94cbd4807c2d58660969e627717133c3052255f4..7a0ba27d4096204f4149d950031c3766f9a2d781 100644 (file)
@@ -110,8 +110,8 @@ class CRM_Activity_Tokens extends \Civi\Token\AbstractTokenSubscriber {
     elseif (isset($actionSearchResult->$field)) {
       $row->tokens($entity, $field, $actionSearchResult->$field);
     }
-    elseif (\CRM_Core_BAO_CustomField::getKeyID($field)) {
-      $row->customToken($entity, $field, $actionSearchResult->entity_id);
+    elseif ($cfID = \CRM_Core_BAO_CustomField::getKeyID($field)) {
+      $row->customToken($entity, $cfID, $actionSearchResult->entity_id);
     }
     else {
       $row->tokens($entity, $field, '');
index 62dcbe5e516e3d14232c2b937f416b559f1128db..40a5c832a9beeb8cf8fc7ec5818c657fc44c27f5 100644 (file)
@@ -136,8 +136,8 @@ class CRM_Contribute_Tokens extends \Civi\Token\AbstractTokenSubscriber {
     elseif (isset($aliasTokens[$field])) {
       $row->dbToken($entity, $field, 'CRM_Contribute_BAO_Contribution', $aliasTokens[$field], $fieldValue);
     }
-    elseif (\CRM_Core_BAO_CustomField::getKeyID($field)) {
-      $row->customToken($entity, $field, $actionSearchResult->entity_id);
+    elseif ($cfID = \CRM_Core_BAO_CustomField::getKeyID($field)) {
+      $row->customToken($entity, $cfID, $actionSearchResult->entity_id);
     }
     else {
       $row->dbToken($entity, $field, 'CRM_Contribute_BAO_Contribution', $field, $fieldValue);
index 923a5414d5efa6ebd6abdce36b9d6319431f5529..e947ade45f79f568c7db28f049ef07f7dddf1f3f 100644 (file)
@@ -142,8 +142,8 @@ LEFT JOIN civicrm_phone phone ON phone.id = lb.phone_id
     elseif (isset($actionSearchResult->$field)) {
       $row->tokens($entity, $field, $actionSearchResult->$field);
     }
-    elseif (\CRM_Core_BAO_CustomField::getKeyID($field)) {
-      $row->customToken($entity, $field, $actionSearchResult->entity_id);
+    elseif ($cfID = \CRM_Core_BAO_CustomField::getKeyID($field)) {
+      $row->customToken($entity, $cfID, $actionSearchResult->entity_id);
     }
     else {
       $row->tokens($entity, $field, '');
index 26adb29f485b4d0076ecda791b7a2800bfccad5a..7fe6496a292d3048d585762cb86eb48f3f696fb8 100644 (file)
@@ -98,8 +98,8 @@ class CRM_Member_Tokens extends \Civi\Token\AbstractTokenSubscriber {
     elseif (isset($actionSearchResult->$field)) {
       $row->tokens($entity, $field, $actionSearchResult->$field);
     }
-    elseif (\CRM_Core_BAO_CustomField::getKeyID($field)) {
-      $row->customToken($entity, $field, $actionSearchResult->entity_id);
+    elseif ($cfID = \CRM_Core_BAO_CustomField::getKeyID($field)) {
+      $row->customToken($entity, $cfID, $actionSearchResult->entity_id);
     }
     else {
       $row->tokens($entity, $field, '');
index 7a2ce239a7c360c5ef68c3c221b91710fdf797be..ccd70813bf00efce9d2f1efa43ae23bc03588896 100644 (file)
@@ -66,7 +66,10 @@ class TokenCompatSubscriber implements EventSubscriberInterface {
         if (!empty($messageTokens['contact'])) {
           foreach ($messageTokens['contact'] as $token) {
             if (\CRM_Core_BAO_CustomField::getKeyID($token)) {
-              $row->customToken('Contact', $token, $contactId);
+              $contact[$token] = civicrm_api3('Contact', 'getvalue', array(
+                'return' => $token,
+                'id' => $contactId,
+              ));
             }
           }
         }
@@ -112,12 +115,12 @@ class TokenCompatSubscriber implements EventSubscriberInterface {
     $e->string = \CRM_Utils_Token::replaceDomainTokens($e->string, \CRM_Core_BAO_Domain::getDomain(), $isHtml, $e->message['tokens'], $useSmarty);
 
     if (!empty($e->context['contact'])) {
-      \CRM_Utils_Token::replaceGreetingTokens($e->string, $e->context['contact'], $e->context['contact']['contact_id'], NULL, FALSE);
-
-      $e->string = \CRM_Utils_Token::replaceContactTokens($e->string, $e->context['contact'], $isHtml, $e->message['tokens'], FALSE, $useSmarty);
+      $e->string = \CRM_Utils_Token::replaceContactTokens($e->string, $e->context['contact'], $isHtml, $e->message['tokens'], TRUE, $useSmarty);
 
       // FIXME: This may depend on $contact being merged with hook values.
       $e->string = \CRM_Utils_Token::replaceHookTokens($e->string, $e->context['contact'], $e->context['hookTokenCategories'], $isHtml, $useSmarty);
+
+      \CRM_Utils_Token::replaceGreetingTokens($e->string, $e->context['contact'], $e->context['contact']['contact_id'], NULL, $useSmarty);
     }
 
     if ($useSmarty) {
index 1a3033a9aca1fba7524f8e4e0d93ba560a5d4754..4f186d3d5c1ea9ccf3d84806cc76e7b8d834554c 100644 (file)
@@ -130,16 +130,23 @@ class TokenRow {
    * Update the value of a custom field token.
    *
    * @param string $entity
-   * @param string $fieldName
-   * @param string $entityID
+   * @param int $customFieldID
+   * @param int $entityID
    * @return TokenRow
    */
-  public function customToken($entity, $fieldName, $entityID) {
+  public function customToken($entity, $customFieldID, $entityID) {
+    $customFieldName = "custom_" . $customFieldID;
     $fieldValue = civicrm_api3($entity, 'getvalue', array(
-      'return' => $fieldName,
+      'return' => $customFieldName,
       'id' => $entityID,
     ));
-    return $this->tokens($entity, $fieldName, $fieldValue);
+
+    // format the raw custom field value into proper display value
+    if ($fieldValue) {
+      $fieldValue = \CRM_Core_BAO_CustomField::displayValue($fieldValue, $customFieldID);
+    }
+
+    return $this->tokens($entity, $customFieldName, $fieldValue);
   }
 
   /**