Skip to content

Commit

Permalink
greeeting token and handle multi-value custom field fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
monishdeb committed Jan 13, 2017
1 parent 4e9b6a6 commit 8640061
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 17 deletions.
4 changes: 2 additions & 2 deletions CRM/Activity/Tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ public function evaluateToken(\Civi\Token\TokenRow $row, $entity, $field, $prefe
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, '');
Expand Down
4 changes: 2 additions & 2 deletions CRM/Contribute/Tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ public function evaluateToken(\Civi\Token\TokenRow $row, $entity, $field, $prefe
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);
Expand Down
4 changes: 2 additions & 2 deletions CRM/Event/Tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ public function evaluateToken(\Civi\Token\TokenRow $row, $entity, $field, $prefe
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, '');
Expand Down
4 changes: 2 additions & 2 deletions CRM/Member/Tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public function evaluateToken(\Civi\Token\TokenRow $row, $entity, $field, $prefe
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, '');
Expand Down
11 changes: 7 additions & 4 deletions Civi/Token/TokenCompatSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ public function onEvaluate(TokenValueEvent $e) {
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,
));
}
}
}
Expand Down Expand Up @@ -112,12 +115,12 @@ public function onRender(TokenRenderEvent $e) {
$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) {
Expand Down
17 changes: 12 additions & 5 deletions Civi/Token/TokenRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,23 @@ public function tokens($a = NULL, $b = NULL, $c = NULL) {
* 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);
}

/**
Expand Down

0 comments on commit 8640061

Please sign in to comment.