3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * Class to abstract token replacement.
21 class CRM_Utils_Token
{
22 public static $_requiredTokens = NULL;
24 public static $_tokens = [
52 // we extract the stuff after the role / permission and return the
53 // civicrm email addresses of all users with that role / permission
54 // useful with rules integration
58 // populate this dynamically
60 // populate this dynamically
61 'contribution' => NULL,
70 'subscribe' => ['group'],
71 'unsubscribe' => ['group'],
72 'resubscribe' => ['group'],
73 'welcome' => ['group'],
78 * This is used by CiviMail but will be made redundant by FlexMailer.
81 public static function getRequiredTokens() {
82 if (self
::$_requiredTokens == NULL) {
83 self
::$_requiredTokens = [
84 'domain.address' => ts("Domain address - displays your organization's postal address."),
85 'action.optOutUrl or action.unsubscribeUrl' => [
86 'action.optOut' => ts("'Opt out via email' - displays an email address for recipients to opt out of receiving emails from your organization."),
87 'action.optOutUrl' => ts("'Opt out via web page' - creates a link for recipients to click if they want to opt out of receiving emails from your organization. Alternatively, you can include the 'Opt out via email' token."),
88 'action.unsubscribe' => ts("'Unsubscribe via email' - displays an email address for recipients to unsubscribe from the specific mailing list used to send this message."),
89 'action.unsubscribeUrl' => ts("'Unsubscribe via web page' - creates a link for recipients to unsubscribe from the specific mailing list used to send this message. Alternatively, you can include the 'Unsubscribe via email' token or one of the Opt-out tokens."),
93 return self
::$_requiredTokens;
97 * Check a string (mailing body) for required tokens.
103 * true if all required tokens are found,
104 * else an array of the missing tokens
106 public static function requiredTokens(&$str) {
107 // FlexMailer is a refactoring of CiviMail which provides new hooks/APIs/docs. If the sysadmin has opted to enable it, then use that instead of CiviMail.
108 $requiredTokens = defined('CIVICRM_FLEXMAILER_HACK_REQUIRED_TOKENS') ? Civi\Core\Resolver
::singleton()->call(CIVICRM_FLEXMAILER_HACK_REQUIRED_TOKENS
, []) : CRM_Utils_Token
::getRequiredTokens();
111 foreach ($requiredTokens as $token => $value) {
112 if (!is_array($value)) {
113 if (!preg_match('/(^|[^\{])' . preg_quote('{' . $token . '}') . '/', $str)) {
114 $missing[$token] = $value;
120 foreach ($value as $t => $d) {
122 if (preg_match('/(^|[^\{])' . preg_quote('{' . $t . '}') . '/', $str)) {
127 $missing[$token] = $desc;
132 if (empty($missing)) {
139 * Wrapper for token matching.
141 * @param string $type
142 * The token type (domain,mailing,contact,action).
144 * The token variable.
146 * The string to search.
151 public static function token_match($type, $var, &$str) {
152 $token = preg_quote('{' . "$type.$var") . '(\|.+?)?' . preg_quote('}');
153 return preg_match("/(^|[^\{])$token/", $str);
157 * Wrapper for token replacing.
159 * @param string $type
162 * The token variable.
163 * @param string $value
164 * The value to substitute for the token.
165 * @param string $str (reference) The string to replace in
167 * @param bool $escapeSmarty
170 * The processed string
172 public static function token_replace($type, $var, $value, &$str, $escapeSmarty = FALSE) {
173 $token = preg_quote('{' . "$type.$var") . '(\|([^\}]+?))?' . preg_quote('}');
178 $value = self
::tokenEscapeSmarty($value);
180 $str = preg_replace("/([^\{])?$token/", "\${1}$value", $str);
185 * Get the regex for token replacement
187 * @param string $token_type
188 * A string indicating the the type of token to be used in the expression.
191 * regular expression suitable for using in preg_replace
193 private static function tokenRegex(string $token_type) {
194 return '/(?<!\{|\\\\)\{' . $token_type . '\.([\w]+(:|\.)?\w*(\-[\w\s]+)?)\}(?!\})/';
198 * Escape the string so a malicious user cannot inject smarty code into the template.
200 * @param string $string
201 * A string that needs to be escaped from smarty parsing.
206 public static function tokenEscapeSmarty($string) {
207 // need to use negative look-behind, as both str_replace() and preg_replace() are sequential
208 return preg_replace(['/{/', '/(?<!{ldelim)}/'], ['{ldelim}', '{rdelim}'], $string);
212 * Replace all the domain-level tokens in $str
215 * The string with tokens to be replaced.
216 * @param object $domain
219 * Replace tokens with HTML or plain text.
221 * @param null $knownTokens
222 * @param bool $escapeSmarty
225 * The processed string
227 public static function replaceDomainTokens(
232 $escapeSmarty = FALSE
236 !$knownTokens ||
empty($knownTokens[$key])
241 $str = preg_replace_callback(
242 self
::tokenRegex($key),
243 function ($matches) use ($domain, $html, $escapeSmarty) {
244 return CRM_Utils_Token
::getDomainTokenReplacement($matches[1], $domain, $html, $escapeSmarty);
252 * @param string $token
253 * @param CRM_Core_BAO_Domain $domain
255 * @param bool $escapeSmarty
257 * @return null|string
259 public static function getDomainTokenReplacement($token, $domain, $html = FALSE, $escapeSmarty = FALSE): ?
string {
260 $tokens = CRM_Core_DomainTokens
::getDomainTokenValues($domain->id
, $html);
261 $value = $tokens[$token] ??
"{domain.$token}";
263 $value = self
::tokenEscapeSmarty($value);
269 * Replace all the org-level tokens in $str
271 * @fixme: This function appears to be broken, as it depended on
272 * nonexistant method: CRM_Core_BAO_CustomValue::getContactValues()
273 * Marking as deprecated until this is clarified.
276 * - the above hard-breakage was there from 2015 to 2021 and
277 * no error was ever reported on it -does that mean
278 * 1) the code is never hit because the only function that
279 * calls this function is never called or
280 * 2) it was called but never required to resolve any tokens
281 * or more specifically custom field tokens
283 * The handling for custom fields with the removed token has
287 * The string with tokens to be replaced.
289 * Associative array of org properties.
291 * Replace tokens with HTML or plain text.
293 * @param bool $escapeSmarty
296 * The processed string
298 public static function replaceOrgTokens($str, &$org, $html = FALSE, $escapeSmarty = FALSE) {
299 CRM_Core_Error
::deprecatedFunctionWarning('token processor');
300 self
::$_tokens['org']
302 array_keys(CRM_Contact_BAO_Contact
::importableFields('Organization')),
303 ['address', 'display_name', 'checksum', 'contact_id']
306 foreach (self
::$_tokens['org'] as $token) {
307 // print "Getting token value for $token<br/><br/>";
312 // If the string doesn't contain this token, skip it.
314 if (!self
::token_match('org', $token, $str)) {
318 // Construct value from $token and $contact
322 if ($token === 'checksum') {
323 $cs = CRM_Contact_BAO_Contact_Utils
::generateChecksum($org['contact_id']);
326 elseif ($token === 'address') {
327 // Build the location values array
330 $loc['display_name'] = CRM_Utils_Array
::retrieveValueRecursive($org, 'display_name');
331 $loc['street_address'] = CRM_Utils_Array
::retrieveValueRecursive($org, 'street_address');
332 $loc['city'] = CRM_Utils_Array
::retrieveValueRecursive($org, 'city');
333 $loc['state_province'] = CRM_Utils_Array
::retrieveValueRecursive($org, 'state_province');
334 $loc['postal_code'] = CRM_Utils_Array
::retrieveValueRecursive($org, 'postal_code');
336 // Construct the address token
338 $value = CRM_Utils_Address
::format($loc);
340 $value = str_replace("\n", '<br />', $value);
344 $value = CRM_Utils_Array
::retrieveValueRecursive($org, $token);
347 self
::token_replace('org', $token, $value, $str, $escapeSmarty);
354 * Replace all mailing tokens in $str
357 * The string with tokens to be replaced.
358 * @param object $mailing
359 * The mailing BAO, or null for validation.
361 * Replace tokens with HTML or plain text.
363 * @param null $knownTokens
364 * @param bool $escapeSmarty
367 * The processed string
369 public static function &replaceMailingTokens(
374 $escapeSmarty = FALSE
377 if (!$knownTokens ||
!isset($knownTokens[$key])) {
381 $str = preg_replace_callback(
382 self
::tokenRegex($key),
383 function ($matches) use (&$mailing, $escapeSmarty) {
384 return CRM_Utils_Token
::getMailingTokenReplacement($matches[1], $mailing, $escapeSmarty);
394 * @param bool $escapeSmarty
398 public static function getMailingTokenReplacement($token, &$mailing, $escapeSmarty = FALSE) {
404 $value = $mailing ?
$mailing->id
: 'undefined';
407 // Key is the ID, or the hash when the hash URLs setting is enabled
409 $value = $mailing->id
;
410 if ($hash = CRM_Mailing_BAO_Mailing
::getMailingHash($value)) {
416 $value = $mailing ?
$mailing->name
: 'Mailing Name';
420 $groups = $mailing ?
$mailing->getGroupNames() : ['Mailing Groups'];
421 $value = implode(', ', $groups);
425 $value = $mailing->subject
;
429 $mailingKey = $mailing->id
;
430 if ($hash = CRM_Mailing_BAO_Mailing
::getMailingHash($mailingKey)) {
433 $value = CRM_Utils_System
::url('civicrm/mailing/view',
434 "reset=1&id={$mailingKey}",
435 TRUE, NULL, FALSE, TRUE
441 // Note: editUrl and scheduleUrl used to be different, but now there's
442 // one screen which can adapt based on permissions (in workflow mode).
443 $value = CRM_Utils_System
::url('civicrm/mailing/send',
444 "reset=1&mid={$mailing->id}&continue=true",
445 TRUE, NULL, FALSE, TRUE
450 $page = new CRM_Mailing_Page_View();
451 $value = $page->run($mailing->id
, NULL, FALSE, TRUE);
454 case 'approvalStatus':
455 $value = CRM_Core_PseudoConstant
::getLabel('CRM_Mailing_DAO_Mailing', 'approval_status_id', $mailing->approval_status_id
);
459 $value = $mailing->approval_note
;
463 $value = CRM_Utils_System
::url('civicrm/mailing/approve',
464 "reset=1&mid={$mailing->id}",
465 TRUE, NULL, FALSE, TRUE
470 $value = CRM_Contact_BAO_Contact
::displayName($mailing->created_id
);
474 $value = CRM_Contact_BAO_Contact
::getPrimaryEmail($mailing->created_id
);
478 $value = "{mailing.$token}";
483 $value = self
::tokenEscapeSmarty($value);
489 * Replace all action tokens in $str
492 * The string with tokens to be replaced.
493 * @param array $addresses
494 * Assoc. array of VERP event addresses.
496 * Assoc. array of action URLs.
498 * Replace tokens with HTML or plain text.
499 * @param array $knownTokens
500 * A list of tokens that are known to exist in the email body.
502 * @param bool $escapeSmarty
505 * The processed string
507 public static function &replaceActionTokens(
513 $escapeSmarty = FALSE
516 // here we intersect with the list of pre-configured valid tokens
517 // so that we remove anything we do not recognize
518 // I hope to move this step out of here soon and
519 // then we will just iterate on a list of tokens that are passed to us
520 if (!$knownTokens ||
empty($knownTokens[$key])) {
524 $str = preg_replace_callback(
525 self
::tokenRegex($key),
526 function ($matches) use (&$addresses, &$urls, $html, $escapeSmarty) {
527 return CRM_Utils_Token
::getActionTokenReplacement($matches[1], $addresses, $urls, $html, $escapeSmarty);
539 * @param bool $escapeSmarty
541 * @return mixed|string
543 public static function getActionTokenReplacement(
548 $escapeSmarty = FALSE
550 // If the token is an email action, use it. Otherwise, find the
553 if (!in_array($token, self
::$_tokens['action'])) {
554 $value = "{action.$token}";
557 $value = $addresses[$token] ??
NULL;
559 if ($value == NULL) {
560 $value = $urls[$token] ??
NULL;
563 if ($value && $html) {
565 if ((substr($token, -3) != 'Url') && ($token != 'forward')) {
566 $value = "mailto:$value";
569 elseif ($value && !$html) {
570 $value = str_replace('&', '&', $value);
575 $value = self
::tokenEscapeSmarty($value);
581 * Replace all the contact-level tokens in $str with information from
585 * The string with tokens to be replaced.
586 * @param array $contact
587 * Associative array of contact properties.
589 * Replace tokens with HTML or plain text.
590 * @param array $knownTokens
591 * A list of tokens that are known to exist in the email body.
592 * @param bool $returnBlankToken
593 * Return unevaluated token if value is null.
595 * @param bool $escapeSmarty
598 * The processed string
600 public static function replaceContactTokens(
605 $returnBlankToken = FALSE,
606 $escapeSmarty = FALSE
608 // Refresh contact tokens in case they have changed. There is heavy caching
609 // in exportable fields so there is no benefit in doing this conditionally.
610 self
::$_tokens['contact'] = array_merge(
611 array_keys(CRM_Contact_BAO_Contact
::exportableFields('All')),
612 ['checksum', 'contact_id']
616 // here we intersect with the list of pre-configured valid tokens
617 // so that we remove anything we do not recognize
618 // I hope to move this step out of here soon and
619 // then we will just iterate on a list of tokens that are passed to us
620 if (!$knownTokens ||
empty($knownTokens[$key])) {
624 $str = preg_replace_callback(
625 self
::tokenRegex($key),
626 function ($matches) use (&$contact, $html, $returnBlankToken, $escapeSmarty) {
627 return CRM_Utils_Token
::getContactTokenReplacement($matches[1], $contact, $html, $returnBlankToken, $escapeSmarty);
632 $str = preg_replace('/\\\\|\{(\s*)?\}/', ' ', $str);
640 * @param bool $returnBlankToken
641 * @param bool $escapeSmarty
643 * @return bool|mixed|null|string
645 public static function getContactTokenReplacement(
649 $returnBlankToken = FALSE,
650 $escapeSmarty = FALSE
652 if (self
::$_tokens['contact'] == NULL) {
653 /* This should come from UF */
655 self
::$_tokens['contact']
657 array_keys(CRM_Contact_BAO_Contact
::exportableFields('All')),
658 ['checksum', 'contact_id']
662 // Construct value from $token and $contact
667 // Support legacy tokens
668 $token = CRM_Utils_Array
::value($token, self
::legacyContactTokens(), $token);
670 // check if the token we were passed is valid
671 // we have to do this because this function is
672 // called only when we find a token in the string
674 if (!in_array(str_replace(':label', '', $token), self
::$_tokens['contact'])) {
677 elseif ($token == 'checksum') {
678 $hash = $contact['hash'] ??
NULL;
679 $contactID = CRM_Utils_Array
::retrieveValueRecursive($contact, 'contact_id');
680 $cs = CRM_Contact_BAO_Contact_Utils
::generateChecksum($contactID,
688 $value = (array) CRM_Utils_Array
::retrieveValueRecursive($contact, str_replace(':label', '', $token));
690 foreach ($value as $index => $item) {
691 $value[$index] = self
::convertPseudoConstantsUsingMetadata($value[$index], str_replace(':label', '', $token));
693 $value = implode(', ', $value);
697 $value = str_replace('&', '&', $value);
700 // if null then return actual token
701 if ($returnBlankToken && !$value) {
706 $value = "{contact.$token}";
710 && !($returnBlankToken && $noReplace)
712 // $returnBlankToken means the caller wants to do further attempts at
713 // processing unreplaced tokens -- so don't escape them yet in this case.
714 $value = self
::tokenEscapeSmarty($value);
721 * Replace all the hook tokens in $str with information from
725 * The string with tokens to be replaced.
726 * @param array $contact
727 * Associative array of contact properties (including hook token values).
730 * Replace tokens with HTML or plain text.
732 * @param bool $escapeSmarty
735 * The processed string
737 public static function &replaceHookTokens(
742 $escapeSmarty = FALSE
745 $categories = self
::getTokenCategories();
747 foreach ($categories as $key) {
748 $str = preg_replace_callback(
749 self
::tokenRegex($key),
750 function ($matches) use (&$contact, $key, $html, $escapeSmarty) {
751 return CRM_Utils_Token
::getHookTokenReplacement($matches[1], $contact, $key, $html, $escapeSmarty);
760 * Get the categories required for rendering tokens.
764 public static function getTokenCategories(): array {
765 if (!isset(\Civi
::$statics[__CLASS__
]['token_categories'])) {
767 \CRM_Utils_Hook
::tokens($tokens);
768 \Civi
::$statics[__CLASS__
]['token_categories'] = array_keys($tokens);
770 return \Civi
::$statics[__CLASS__
]['token_categories'];
774 * Parse html through Smarty resolving any smarty functions.
775 * @param string $tokenHtml
776 * @param array $entity
777 * @param string $entityType
779 * html parsed through smarty
782 public static function parseThroughSmarty($tokenHtml, $entity, $entityType = 'contact') {
783 if (defined('CIVICRM_MAIL_SMARTY') && CIVICRM_MAIL_SMARTY
) {
784 $smarty = CRM_Core_Smarty
::singleton();
785 // also add the tokens to the template
786 $smarty->assign_by_ref($entityType, $entity);
787 $tokenHtml = $smarty->fetch("string:$tokenHtml");
797 * @param bool $escapeSmarty
799 * @return mixed|string
801 public static function getHookTokenReplacement(
806 $escapeSmarty = FALSE
808 $value = $contact["{$category}.{$token}"] ??
NULL;
810 if ($value && !$html) {
811 $value = str_replace('&', '&', $value);
815 $value = self
::tokenEscapeSmarty($value);
822 * unescapeTokens removes any characters that caused the replacement routines to skip token replacement
823 * for example {{token}} or \{token} will result in {token} in the final email
825 * this routine will remove the extra backslashes and braces
829 * @param $str ref to the string that will be scanned and modified
831 public static function unescapeTokens(&$str) {
832 $str = preg_replace('/\\\\|\{(\{\w+\.\w+\})\}/', '\\1', $str);
836 * Replace unsubscribe tokens.
839 * The string with tokens to be replaced.
840 * @param object $domain
842 * @param array $groups
843 * The groups (if any) being unsubscribed.
845 * Replace tokens with html or plain text.
846 * @param int $contact_id
848 * @param string $hash The security hash of the unsub event
851 * The processed string
853 public static function &replaceUnsubscribeTokens(
861 if (self
::token_match('unsubscribe', 'group', $str)) {
862 if (!empty($groups)) {
863 $config = CRM_Core_Config
::singleton();
864 $base = CRM_Utils_System
::baseURL();
866 // FIXME: an ugly hack for CRM-2035, to be dropped once CRM-1799 is implemented
867 $dao = new CRM_Contact_DAO_Group();
869 while ($dao->fetch()) {
870 if (substr($dao->visibility
, 0, 6) == 'Public') {
871 $visibleGroups[] = $dao->id
;
874 $value = implode(', ', $groups);
875 self
::token_replace('unsubscribe', 'group', $value, $str);
882 * Replace resubscribe tokens.
885 * The string with tokens to be replaced.
886 * @param object $domain
888 * @param array $groups
889 * The groups (if any) being resubscribed.
891 * Replace tokens with html or plain text.
892 * @param int $contact_id
894 * @param string $hash The security hash of the resub event
897 * The processed string
899 public static function &replaceResubscribeTokens(
900 $str, &$domain, &$groups, $html,
903 if (self
::token_match('resubscribe', 'group', $str)) {
904 if (!empty($groups)) {
905 $value = implode(', ', $groups);
906 self
::token_replace('resubscribe', 'group', $value, $str);
913 * Replace subscription-confirmation-request tokens
916 * The string with tokens to be replaced.
917 * @param string $group
918 * The name of the group being subscribed.
921 * Replace tokens with html or plain text.
924 * The processed string
926 public static function &replaceSubscribeTokens($str, $group, $url, $html) {
927 if (self
::token_match('subscribe', 'group', $str)) {
928 self
::token_replace('subscribe', 'group', $group, $str);
930 if (self
::token_match('subscribe', 'url', $str)) {
931 self
::token_replace('subscribe', 'url', $url, $str);
937 * Replace subscription-invitation tokens
940 * The string with tokens to be replaced.
943 * The processed string
945 public static function &replaceSubscribeInviteTokens($str) {
946 if (preg_match('/\{action\.subscribeUrl\}/', $str)) {
947 $url = CRM_Utils_System
::url('civicrm/mailing/subscribe',
949 TRUE, NULL, FALSE, TRUE
951 $str = preg_replace('/\{action\.subscribeUrl\}/', $url, $str);
954 if (preg_match('/\{action\.subscribeUrl.\d+\}/', $str, $matches)) {
955 foreach ($matches as $key => $value) {
956 $gid = substr($value, 21, -1);
957 $url = CRM_Utils_System
::url('civicrm/mailing/subscribe',
958 "reset=1&gid={$gid}",
959 TRUE, NULL, FALSE, TRUE
961 $str = preg_replace('/' . preg_quote($value) . '/', $url, $str);
965 if (preg_match('/\{action\.subscribe.\d+\}/', $str, $matches)) {
966 foreach ($matches as $key => $value) {
967 $gid = substr($value, 18, -1);
968 $config = CRM_Core_Config
::singleton();
969 $domain = CRM_Core_BAO_MailSettings
::defaultDomain();
970 $localpart = CRM_Core_BAO_MailSettings
::defaultLocalpart();
971 // we add the 0.0000000000000000 part to make this match the other email patterns (with action, two ids and a hash)
972 $str = preg_replace('/' . preg_quote($value) . '/', "mailto:{$localpart}s.{$gid}.0.0000000000000000@$domain", $str);
979 * Replace welcome/confirmation tokens
982 * The string with tokens to be replaced.
983 * @param string $group
984 * The name of the group being subscribed.
986 * Replace tokens with html or plain text.
989 * The processed string
991 public static function &replaceWelcomeTokens($str, $group, $html) {
992 if (self
::token_match('welcome', 'group', $str)) {
993 self
::token_replace('welcome', 'group', $group, $str);
999 * Find unprocessed tokens (call this last)
1001 * @param string $str
1002 * The string to search.
1005 * Array of tokens that weren't replaced
1007 public static function &unmatchedTokens(&$str) {
1008 //preg_match_all('/[^\{\\\\]\{(\w+\.\w+)\}[^\}]/', $str, $match);
1009 preg_match_all('/\{(\w+\.\w+)\}/', $str, $match);
1014 * Find and replace tokens for each component.
1016 * @param string $str
1017 * The string to search.
1018 * @param array $contact
1019 * Associative array of contact properties.
1020 * @param array $components
1021 * A list of tokens that are known to exist in the email body.
1023 * @param bool $escapeSmarty
1024 * @param bool $returnEmptyToken
1027 * The processed string
1031 public static function replaceComponentTokens(&$str, $contact, $components, $escapeSmarty = FALSE, $returnEmptyToken = TRUE) {
1032 CRM_Core_Error
::deprecatedFunctionWarning('use the token processor');
1033 if (!is_array($components) ||
empty($contact)) {
1037 foreach ($components as $name => $tokens) {
1038 if (!is_array($tokens) ||
empty($tokens)) {
1042 foreach ($tokens as $token) {
1043 if (self
::token_match($name, $token, $str) && isset($contact[$name . '.' . $token])) {
1044 self
::token_replace($name, $token, $contact[$name . '.' . $token], $str, $escapeSmarty);
1046 elseif (!$returnEmptyToken) {
1047 //replacing empty token
1048 self
::token_replace($name, $token, "", $str, $escapeSmarty);
1056 * Get array of string tokens.
1058 * @param string $string
1059 * The input string to parse for tokens.
1062 * array of tokens mentioned in field
1064 public static function getTokens($string) {
1067 preg_match_all('/(?<!\{|\\\\)\{(\w+\.\w+(:|.)?\w*)\}(?!\})/',
1074 foreach ($matches[1] as $token) {
1075 $parts = explode('.', $token, 3);
1078 $suffix = !empty($parts[2]) ?
('.' . $parts[2]) : '';
1079 if ($name && $type) {
1080 if (!isset($tokens[$type])) {
1081 $tokens[$type] = [];
1083 $tokens[$type][] = $name . $suffix;
1091 * Function to determine which values to retrieve to insert into tokens. The heavy resemblance between this function
1092 * and getTokens appears to be historical rather than intentional and should be reviewed
1095 * fields to pass in as return properties when populating token
1097 public static function getReturnProperties(&$string) {
1098 $returnProperties = [];
1100 preg_match_all('/(?<!\{|\\\\)\{(\w+\.\w+)\}(?!\})/',
1106 foreach ($matches[1] as $token) {
1107 [$type, $name] = preg_split('/\./', $token, 2);
1109 $returnProperties["{$name}"] = 1;
1114 return $returnProperties;
1118 * Gives required details of contacts in an indexed array format so we
1119 * can iterate in a nice loop and do token evaluation
1121 * @param array $contactIDs
1122 * @param array $returnProperties
1123 * Of required properties.
1124 * @param bool $skipOnHold Don't return on_hold contact info also.
1125 * Don't return on_hold contact info also.
1126 * @param bool $skipDeceased Don't return deceased contact info.
1127 * Don't return deceased contact info.
1128 * @param array $extraParams
1129 * Extra params - DEPRECATED
1130 * @param array $tokens
1131 * The list of tokens we've extracted from the content.
1132 * @param string|null $className
1133 * @param int|null $jobID
1134 * The mailing list jobID - this is a legacy param.
1136 * @return array - e.g [[1 => ['first_name' => 'bob'...], 34 => ['first_name' => 'fred'...]]]
1138 public static function getTokenDetails(
1140 $returnProperties = NULL,
1142 $skipDeceased = TRUE,
1143 $extraParams = NULL,
1150 foreach ($contactIDs as $contactID) {
1152 CRM_Core_Form
::CB_PREFIX
. $contactID,
1161 if ($skipDeceased) {
1162 $params[] = ['is_deceased', '=', 0, 0, 0];
1167 $params[] = ['on_hold', '=', 0, 0, 0];
1171 CRM_Core_Error
::deprecatedWarning('Passing $extraParams to getTokenDetails() is not supported and will be removed in a future version');
1172 $params = array_merge($params, $extraParams);
1175 // if return properties are not passed then get all return properties
1176 if (empty($returnProperties)) {
1177 $fields = array_merge(array_keys(CRM_Contact_BAO_Contact
::exportableFields()),
1178 ['display_name', 'checksum', 'contact_id']
1180 foreach ($fields as $val) {
1181 // The unavailable fields are not available as tokens, do not have a one-2-one relationship
1182 // with contacts and are expensive to resolve.
1183 // @todo see CRM-17253 - there are some other fields (e.g note) that should be excluded
1184 // and upstream calls to this should populate return properties.
1185 $unavailableFields = ['group', 'tag'];
1186 if (!in_array($val, $unavailableFields)) {
1187 $returnProperties[$val] = 1;
1193 foreach ($returnProperties as $name => $dontCare) {
1194 $cfID = CRM_Core_BAO_CustomField
::getKeyID($name);
1200 [$contactDetails] = CRM_Contact_BAO_Query
::apiQuery($params, $returnProperties, NULL, NULL, 0, count($contactIDs), TRUE, FALSE, TRUE, CRM_Contact_BAO_Query
::MODE_CONTACTS
, NULL, TRUE);
1202 foreach ($contactIDs as $contactID) {
1203 if (array_key_exists($contactID, $contactDetails)) {
1204 if (!empty($contactDetails[$contactID]['preferred_communication_method'])
1206 $communicationPreferences = [];
1207 foreach ((array) $contactDetails[$contactID]['preferred_communication_method'] as $val) {
1209 $communicationPreferences[$val] = CRM_Core_PseudoConstant
::getLabel('CRM_Contact_DAO_Contact', 'preferred_communication_method', $val);
1212 $contactDetails[$contactID]['preferred_communication_method'] = implode(', ', $communicationPreferences);
1215 foreach ($custom as $cfID) {
1216 if (isset($contactDetails[$contactID]["custom_{$cfID}"])) {
1217 $contactDetails[$contactID]["custom_{$cfID}"] = CRM_Core_BAO_CustomField
::displayValue($contactDetails[$contactID]["custom_{$cfID}"], $cfID);
1221 // special case for greeting replacement
1227 if (!empty($contactDetails[$contactID][$val])) {
1228 $contactDetails[$contactID][$val] = $contactDetails[$contactID]["{$val}_display"];
1234 // $contactDetails = &$details[0] = is an array of [ contactID => contactDetails ]
1235 // also call a hook and get token details
1236 CRM_Utils_Hook
::tokenValues($contactDetails,
1242 return [$contactDetails];
1246 * Call hooks on tokens for anonymous users - contact id is set to 0 - this allows non-contact
1247 * specific tokens to be rendered
1249 * @param array $contactIDs
1250 * This should always be array(0) or its not anonymous - left to keep signature same.
1252 * @param string $returnProperties
1253 * @param bool $skipOnHold
1254 * @param bool $skipDeceased
1255 * @param string $extraParams
1256 * @param array $tokens
1257 * @param string $className
1258 * Sent as context to the hook.
1259 * @param string $jobID
1261 * contactDetails with hooks swapped out
1263 public static function getAnonymousTokenDetails($contactIDs = [0],
1264 $returnProperties = NULL,
1266 $skipDeceased = TRUE,
1267 $extraParams = NULL,
1271 $details = [0 => []];
1272 // also call a hook and get token details
1273 CRM_Utils_Hook
::tokenValues($details[0],
1283 * Get Membership Token Details.
1284 * @param array $membershipIDs
1285 * Array of membership IDS.
1289 public static function getMembershipTokenDetails($membershipIDs) {
1290 $memberships = civicrm_api3('membership', 'get', [
1291 'options' => ['limit' => 0],
1292 'membership_id' => ['IN' => (array) $membershipIDs],
1294 return $memberships['values'];
1298 * Replace existing greeting tokens in message/subject.
1300 * This function operates by reference, modifying the first parameter. Other
1301 * methods for token replacement in this class return the modified string.
1302 * This leads to inconsistency in how these methods must be applied.
1304 * @TODO Remove that inconsistency in usage.
1306 * ::replaceContactTokens() may need to be called after this method, to
1307 * replace tokens supplied from this method.
1309 * @param string $tokenString
1310 * @param array $contactDetails
1311 * @param int $contactId
1312 * @param string $className
1313 * @param bool $escapeSmarty
1315 public static function replaceGreetingTokens(&$tokenString, $contactDetails = NULL, $contactId = NULL, $className = NULL, $escapeSmarty = FALSE) {
1317 if (!$contactDetails && !$contactId) {
1321 // check if there are any tokens
1322 $greetingTokens = self
::getTokens($tokenString);
1324 if (!empty($greetingTokens)) {
1325 // first use the existing contact object for token replacement
1326 if (!empty($contactDetails)) {
1327 $tokenString = CRM_Utils_Token
::replaceContactTokens($tokenString, $contactDetails, TRUE, $greetingTokens, TRUE, $escapeSmarty);
1330 self
::removeNullContactTokens($tokenString, $contactDetails, $greetingTokens);
1331 // check if there are any unevaluated tokens
1332 $greetingTokens = self
::getTokens($tokenString);
1334 // $greetingTokens not empty, means there are few tokens which are not
1335 // evaluated, like custom data etc
1336 // so retrieve it from database
1337 if (!empty($greetingTokens) && array_key_exists('contact', $greetingTokens)) {
1338 $greetingsReturnProperties = array_flip(CRM_Utils_Array
::value('contact', $greetingTokens));
1339 $greetingsReturnProperties = array_fill_keys(array_keys($greetingsReturnProperties), 1);
1340 $contactParams = ['contact_id' => $contactId];
1342 $greetingDetails = self
::getTokenDetails($contactParams,
1343 $greetingsReturnProperties,
1349 // again replace tokens
1350 $tokenString = CRM_Utils_Token
::replaceContactTokens($tokenString,
1359 // check if there are still any unevaluated tokens
1360 $remainingTokens = self
::getTokens($tokenString);
1362 // $greetingTokens not empty, there are customized or hook tokens to replace
1363 if (!empty($remainingTokens)) {
1364 // Fill the return properties array
1365 $greetingTokens = $remainingTokens;
1366 reset($greetingTokens);
1367 $greetingsReturnProperties = [];
1368 foreach ($greetingTokens as $value) {
1369 $props = array_flip($value);
1370 $props = array_fill_keys(array_keys($props), 1);
1371 $greetingsReturnProperties = $greetingsReturnProperties +
$props;
1373 $contactParams = ['contact_id' => $contactId];
1374 $greetingDetails = self
::getTokenDetails($contactParams,
1375 $greetingsReturnProperties,
1380 // Prepare variables for calling replaceHookTokens
1381 $categories = array_keys($greetingTokens);
1382 [$contact] = $greetingDetails;
1383 // Replace tokens defined in Hooks.
1384 $tokenString = CRM_Utils_Token
::replaceHookTokens($tokenString, $contact[$contactId], $categories);
1390 * At this point, $contactDetails has loaded the contact from the DAO. Any
1391 * (non-custom) missing fields are null. By removing them, we can avoid
1392 * expensive calls to CRM_Contact_BAO_Query.
1394 * @param string $tokenString
1395 * @param array $contactDetails
1396 * @param array $greetingTokens
1398 private static function removeNullContactTokens(&$tokenString, $contactDetails, &$greetingTokens) {
1400 // Only applies to contact tokens
1401 if (!array_key_exists('contact', $greetingTokens)) {
1405 $greetingTokensOriginal = $greetingTokens;
1406 $contactFieldList = CRM_Contact_DAO_Contact
::fields();
1407 // Sometimes contactDetails are in a multidemensional array, sometimes a
1408 // single-dimension array.
1409 if (array_key_exists(0, $contactDetails) && is_array($contactDetails[0])) {
1410 $contactDetails = current($contactDetails[0]);
1412 $nullFields = array_keys(array_diff_key($contactFieldList, $contactDetails));
1414 // Handle legacy tokens
1415 foreach (self
::legacyContactTokens() as $oldToken => $newToken) {
1416 if (CRM_Utils_Array
::key($newToken, $nullFields)) {
1417 $nullFields[] = $oldToken;
1421 // Remove null contact fields from $greetingTokens
1422 $greetingTokens['contact'] = array_diff($greetingTokens['contact'], $nullFields);
1424 // Also remove them from $tokenString
1425 $removedTokens = array_diff($greetingTokensOriginal['contact'], $greetingTokens['contact']);
1426 // Handle legacy tokens again, sigh
1427 if (!empty($removedTokens)) {
1428 foreach ($removedTokens as $token) {
1429 if (CRM_Utils_Array
::value($token, self
::legacyContactTokens()) !== NULL) {
1430 $removedTokens[] = CRM_Utils_Array
::value($token, self
::legacyContactTokens());
1433 foreach ($removedTokens as $token) {
1434 $tokenString = str_replace("{contact.$token}", '', $tokenString);
1444 public static function flattenTokens(&$tokens) {
1445 $flattenTokens = [];
1452 if (!isset($tokens[$prop])) {
1455 foreach ($tokens[$prop] as $type => $names) {
1456 if (!isset($flattenTokens[$type])) {
1457 $flattenTokens[$type] = [];
1459 foreach ($names as $name) {
1460 $flattenTokens[$type][$name] = 1;
1465 return $flattenTokens;
1469 * Replace all user tokens in $str
1471 * @param string $str
1472 * The string with tokens to be replaced.
1474 * @param null $knownTokens
1475 * @param bool $escapeSmarty
1478 * The processed string
1480 public static function &replaceUserTokens($str, $knownTokens = NULL, $escapeSmarty = FALSE) {
1482 if (!$knownTokens ||
1483 !isset($knownTokens[$key])
1488 $str = preg_replace_callback(
1489 self
::tokenRegex($key),
1490 function ($matches) use ($escapeSmarty) {
1491 return CRM_Utils_Token
::getUserTokenReplacement($matches[1], $escapeSmarty);
1500 * @param bool $escapeSmarty
1504 public static function getUserTokenReplacement($token, $escapeSmarty = FALSE) {
1507 [$objectName, $objectValue] = explode('-', $token, 2);
1509 switch ($objectName) {
1511 $value = CRM_Core_Permission
::permissionEmails($objectValue);
1515 $value = CRM_Core_Permission
::roleEmails($objectValue);
1519 if ($escapeSmarty) {
1520 $value = self
::tokenEscapeSmarty($value);
1529 * Do not use this function - it still needs full removal from active code
1530 * in CRM_Contribute_Form_Task_PDFLetter.
1532 protected static function _buildContributionTokens() {
1533 $key = 'contribution';
1535 if (!isset(Civi
::$statics[__CLASS__
][__FUNCTION__
][$key])) {
1536 $tokens = array_merge(CRM_Contribute_BAO_Contribution
::exportableFields('All'),
1537 ['campaign' => [], 'financial_type' => [], 'payment_instrument' => []],
1538 self
::getCustomFieldTokens('Contribution'),
1540 'financial_type_id:label',
1541 'financial_type_id:name',
1542 'contribution_page_id:label',
1543 'contribution_page_id:name',
1544 'payment_instrument_id:label',
1545 'payment_instrument_id:name',
1547 'is_pay_later:label',
1548 'contribution_status_id:label',
1549 'contribution_status_id:name',
1550 'is_template:label',
1553 foreach ($tokens as $token) {
1554 if (!empty($token['name'])) {
1555 $tokens[$token['name']] = [];
1558 Civi
::$statics[__CLASS__
][__FUNCTION__
][$key] = array_keys($tokens);
1560 self
::$_tokens[$key] = Civi
::$statics[__CLASS__
][__FUNCTION__
][$key];
1568 * Replace tokens for an entity.
1569 * @param string $entity
1570 * @param array $entityArray
1571 * (e.g. in format from api).
1572 * @param string $str
1573 * String to replace in.
1574 * @param array $knownTokens
1575 * Array of tokens present.
1576 * @param bool $escapeSmarty
1578 * string with replacements made
1580 public static function replaceEntityTokens($entity, $entityArray, $str, $knownTokens = [], $escapeSmarty = FALSE) {
1581 if (!$knownTokens ||
empty($knownTokens[$entity])) {
1585 $fn = 'get' . ucfirst($entity) . 'TokenReplacement';
1586 $fn = is_callable(['CRM_Utils_Token', $fn]) ?
$fn : 'getApiTokenReplacement';
1587 // since we already know the tokens lets just use them & do str_replace which is faster & simpler than preg_replace
1588 foreach ($knownTokens[$entity] as $token) {
1589 // We are now supporting the syntax case_type_id:label
1590 // so strip anything after the ':'
1591 // (we aren't supporting 'name' at this stage, so we can assume 'label'
1592 // test cover in TokenConsistencyTest.
1593 $parts = explode(':', $token);
1594 $replacement = self
::$fn($entity, $parts[0], $entityArray);
1595 if ($escapeSmarty) {
1596 $replacement = self
::tokenEscapeSmarty($replacement);
1598 $str = str_replace('{' . $entity . '.' . $token . '}', $replacement, $str);
1600 return preg_replace('/\\\\|\{(\s*)?\}/', ' ', $str);
1606 * @param int $caseId
1607 * @param string $str
1608 * @param array $knownTokens
1609 * @param bool $escapeSmarty
1611 * @throws \CiviCRM_API3_Exception
1613 public static function replaceCaseTokens($caseId, $str, $knownTokens = NULL, $escapeSmarty = FALSE): string {
1614 if (strpos($str, '{case.') === FALSE) {
1617 if (!$knownTokens) {
1618 $knownTokens = self
::getTokens($str);
1620 $case = civicrm_api3('case', 'getsingle', ['id' => $caseId]);
1621 return self
::replaceEntityTokens('case', $case, $str, $knownTokens, $escapeSmarty);
1625 * Generic function for formatting token replacement for an api field
1629 * @param string $entity
1630 * @param string $token
1631 * @param array $entityArray
1633 * @throws \CiviCRM_API3_Exception
1635 public static function getApiTokenReplacement($entity, $token, $entityArray) {
1636 if (!isset($entityArray[$token])) {
1639 $field = civicrm_api3($entity, 'getfield', ['action' => 'get', 'name' => $token, 'get_options' => 'get']);
1640 $field = $field['values'];
1641 $fieldType = $field['type'] ??
NULL;
1643 if ($fieldType == CRM_Utils_Type
::T_BOOLEAN
&& empty($field['options'])) {
1644 $field['options'] = [ts('No'), ts('Yes')];
1646 // Match pseudoconstants
1647 if (!empty($field['options'])) {
1649 foreach ((array) $entityArray[$token] as $val) {
1650 $ret[] = $field['options'][$val];
1652 return implode(', ', $ret);
1654 // Format date fields
1655 elseif ($entityArray[$token] && in_array($fieldType, [CRM_Utils_Type
::T_DATE
, CRM_Utils_Type
::T_TIMESTAMP
, (CRM_Utils_Type
::T_DATE + CRM_Utils_Type
::T_TIME
)])) {
1656 return CRM_Utils_Date
::customFormat($entityArray[$token]);
1658 return implode(', ', (array) $entityArray[$token]);
1662 * Do not use - unused in core.
1664 * Replace Contribution tokens in html.
1666 * @param string $str
1667 * @param array $contribution
1668 * @param bool|string $html
1669 * @param string $knownTokens
1670 * @param bool|string $escapeSmarty
1676 public static function replaceContributionTokens($str, &$contribution, $html = FALSE, $knownTokens = NULL, $escapeSmarty = FALSE) {
1677 $key = 'contribution';
1678 if (!$knownTokens ||
empty($knownTokens[$key])) {
1683 // here we intersect with the list of pre-configured valid tokens
1684 // so that we remove anything we do not recognize
1685 // I hope to move this step out of here soon and
1686 // then we will just iterate on a list of tokens that are passed to us
1688 $str = preg_replace_callback(
1689 self
::tokenRegex($key),
1690 function ($matches) use (&$contribution, $html, $escapeSmarty) {
1691 return CRM_Utils_Token
::getContributionTokenReplacement($matches[1], $contribution, $html, $escapeSmarty);
1696 $str = preg_replace('/\\\\|\{(\s*)?\}/', ' ', $str);
1701 * We have a situation where we are rendering more than one token in each field because we are combining
1702 * tokens from more than one contribution when pdf thank you letters are grouped (CRM-14367)
1704 * The replaceContributionToken doesn't handle receive_date correctly in this scenario because of the formatting
1705 * it applies (other tokens are OK including date fields)
1707 * So we sort this out & then call the main function. Note that we are not escaping smarty on this fields like the main function
1708 * does - but the fields is already being formatted through a date function
1710 * @param string $separator
1711 * @param string $str
1712 * @param array $contributions
1713 * @param array $knownTokens
1719 public static function replaceMultipleContributionTokens(string $separator, string $str, array $contributions, array $knownTokens): string {
1720 CRM_Core_Error
::deprecatedFunctionWarning('no alternative');
1721 foreach ($knownTokens['contribution'] ??
[] as $token) {
1722 $resolvedTokens = [];
1723 foreach ($contributions as $contribution) {
1724 $resolvedTokens[] = self
::replaceContributionTokens('{contribution.' . $token . '}', $contribution, FALSE, $knownTokens);
1726 $str = self
::token_replace('contribution', $token, implode($separator, $resolvedTokens), $str);
1732 * Get replacement strings for any membership tokens (only a small number of tokens are implemnted in the first instance
1733 * - this is used by the pdfLetter task from membership search
1735 * This is called via replaceEntityTokens.
1737 * In the near term it will not be called at all from core as
1738 * the pdf letter task is updated to use the processor.
1742 * @param string $entity
1743 * should always be "membership"
1744 * @param string $token
1746 * @param array $membership
1747 * An api result array for a single membership.
1748 * @return string token replacement
1750 public static function getMembershipTokenReplacement($entity, $token, $membership) {
1751 $supportedTokens = [
1756 'membership_type_id',
1764 // membership_type_id would only be requested if the calling
1765 // class is mapping it to '{membership:membership_type_id:label'}
1766 case 'membership_type_id':
1767 $value = $membership['membership_name'];
1771 // status_id would only be requested if the calling
1772 // class is mapping it to '{membership:status_id:label'}
1774 $statuses = CRM_Member_BAO_Membership
::buildOptions('status_id');
1775 $value = $statuses[$membership['status_id']];
1780 $value = civicrm_api3('membership_type', 'getvalue', [
1781 'id' => $membership['membership_type_id'],
1782 'return' => 'minimum_fee',
1784 $value = CRM_Utils_Money
::format($value, NULL, NULL, TRUE);
1786 catch (CiviCRM_API3_Exception
$e) {
1787 // we can anticipate we will get an error if the minimum fee is set to 'NULL' because of the way the
1788 // api handles NULL (4.4)
1794 if (in_array($token, $supportedTokens)) {
1795 $value = $membership[$token];
1796 if (CRM_Utils_String
::endsWith($token, '_date')) {
1797 $value = CRM_Utils_Date
::customFormat($value);
1802 $value = "{$entity}.{$token}";
1811 * Do not use - unused in core.
1814 * @param $contribution
1816 * @param bool $escapeSmarty
1820 * @return mixed|string
1821 * @throws \CRM_Core_Exception
1823 public static function getContributionTokenReplacement($token, $contribution, $html = FALSE, $escapeSmarty = FALSE) {
1824 self
::_buildContributionTokens();
1827 case 'total_amount':
1830 case 'non_deductible_amount':
1831 // FIXME: Is this ever a multi-dimensional array? Why use retrieveValueRecursive()?
1832 $amount = CRM_Utils_Array
::retrieveValueRecursive($contribution, $token);
1833 $currency = CRM_Utils_Array
::retrieveValueRecursive($contribution, 'currency');
1834 $value = CRM_Utils_Money
::format($amount, $currency);
1837 case 'receive_date':
1838 case 'receipt_date':
1839 $value = CRM_Utils_Array
::retrieveValueRecursive($contribution, $token);
1840 $config = CRM_Core_Config
::singleton();
1841 $value = CRM_Utils_Date
::customFormat($value, $config->dateformatDatetime
);
1845 $value = CRM_Utils_Array
::retrieveValueRecursive($contribution, 'contribution_source');
1849 if (!in_array($token, self
::$_tokens['contribution'])) {
1850 $value = "{contribution.$token}";
1853 $value = CRM_Utils_Array
::retrieveValueRecursive($contribution, $token);
1858 if ($escapeSmarty) {
1859 $value = self
::tokenEscapeSmarty($value);
1866 * [legacy_token => new_token]
1868 public static function legacyContactTokens() {
1870 'individual_prefix' => 'prefix_id',
1871 'individual_suffix' => 'suffix_id',
1872 'gender' => 'gender_id',
1873 'communication_style' => 'communication_style_id',
1878 * Get all custom field tokens of $entity
1882 * @param string $entity
1884 * return custom field tokens in array('custom_N' => 'label') format
1886 public static function getCustomFieldTokens($entity) {
1888 foreach (CRM_Core_BAO_CustomField
::getFields($entity) as $id => $info) {
1889 $customTokens['custom_' . $id] = $info['label'] . ' :: ' . $info['groupTitle'];
1891 return $customTokens;
1895 * Formats a token list for the select2 widget
1900 public static function formatTokensForDisplay($tokens) {
1901 $sorted = $output = [];
1903 // Sort in ascending order by ignoring word case
1904 natcasesort($tokens);
1906 // Attempt to place tokens into optgroups
1907 // @todo These groupings could be better and less hackish. Getting them pre-grouped from upstream would be nice.
1908 foreach ($tokens as $k => $v) {
1909 // Check to see if this token is already in a group e.g. for custom fields
1910 $split = explode(' :: ', $v);
1911 if (!empty($split[1])) {
1912 $sorted[$split[1]][] = ['id' => $k, 'text' => $split[0]];
1916 $split = explode('.', trim($k, '{}'));
1917 if (isset($split[1])) {
1918 $entity = array_key_exists($split[1], CRM_Core_DAO_Address
::export()) ?
'Address' : ucwords(str_replace('_', ' ', $split[0]));
1921 $entity = 'Contact';
1923 $sorted[ts($entity)][] = ['id' => $k, 'text' => $v];
1928 foreach ($sorted as $k => $v) {
1929 $output[] = ['text' => $k, 'children' => $v];
1939 * @return bool|int|mixed|string|null
1941 protected static function convertPseudoConstantsUsingMetadata($value, $token) {
1942 // Convert pseudoconstants using metadata
1943 if ($value && is_numeric($value)) {
1944 $allFields = CRM_Contact_BAO_Contact
::exportableFields('All');
1945 if (!empty($allFields[$token]['pseudoconstant'])) {
1946 $value = CRM_Core_PseudoConstant
::getLabel('CRM_Contact_BAO_Contact', $token, $value);
1949 elseif ($value && CRM_Utils_String
::endsWith($token, '_date')) {
1950 $value = CRM_Utils_Date
::customFormat($value);
1956 * Get token deprecation information.
1960 public static function getTokenDeprecations(): array {
1962 'WorkFlowMessageTemplates' => [
1963 'contribution_invoice_receipt' => [
1964 '$display_name' => 'contact.display_name',
1966 'contribution_online_receipt' => [
1967 '$contributeMode' => 'no longer available / relevant',
1968 '$first_name' => 'contact.first_name',
1969 '$last_name' => 'contact.last_name',
1970 '$displayName' => 'contact.display_name',