* Class to abstract token replacement.
*/
class CRM_Utils_Token {
- static $_requiredTokens = NULL;
+ public static $_requiredTokens = NULL;
- static $_tokens = [
+ public static $_tokens = [
'action' => [
'forward',
'optOut',
'welcome' => ['group'],
];
-
/**
* @deprecated
* This is used by CiviMail but will be made redundant by FlexMailer.
* The message.
*
* @return bool|array
- * true if all required tokens are found,
+ * true if all required tokens are found,
* else an array of the missing tokens
*/
public static function requiredTokens(&$str) {
* The token variable.
* @param string $value
* The value to substitute for the token.
- * @param string (reference) $str The string to replace in
+ * @param string $str (reference) The string to replace in
*
* @param bool $escapeSmarty
*
// special case for greeting replacement
foreach ([
- 'email_greeting',
- 'postal_greeting',
- 'addressee',
- ] as $val) {
+ 'email_greeting',
+ 'postal_greeting',
+ 'addressee',
+ ] as $val) {
if (!empty($contactDetails[$contactID][$val])) {
$contactDetails[$contactID][$val] = $contactDetails[$contactID]["{$val}_display"];
}
* contactDetails with hooks swapped out
*/
public static function getAnonymousTokenDetails($contactIDs = [
- 0,
- ],
+ 0,
+ ],
$returnProperties = NULL,
$skipOnHold = TRUE,
$skipDeceased = TRUE,
*
* @param string $tokenString
* @param array $contactDetails
+ * @param array $greetingTokens
*/
private static function removeNullContactTokens(&$tokenString, $contactDetails, &$greetingTokens) {
+
+ // Only applies to contact tokens
+ if (!array_key_exists('contact', $greetingTokens)) {
+ return;
+ }
+
$greetingTokensOriginal = $greetingTokens;
$contactFieldList = CRM_Contact_DAO_Contact::fields();
// Sometimes contactDetails are in a multidemensional array, sometimes a
$flattenTokens = [];
foreach ([
- 'html',
- 'text',
- 'subject',
- ] as $prop) {
+ 'html',
+ 'text',
+ 'subject',
+ ] as $prop) {
if (!isset($tokens[$prop])) {
continue;
}
public static function replaceContributionTokens($str, &$contribution, $html = FALSE, $knownTokens = NULL, $escapeSmarty = FALSE) {
$key = 'contribution';
if (!$knownTokens || !CRM_Utils_Array::value($key, $knownTokens)) {
- return $str; //early return
+ //early return
+ return $str;
}
self::_buildContributionTokens();
case 'fee':
try {
$value = civicrm_api3('membership_type', 'getvalue', [
- 'id' => $membership['membership_type_id'],
- 'return' => 'minimum_fee',
- ]);
+ 'id' => $membership['membership_type_id'],
+ 'return' => 'minimum_fee',
+ ]);
$value = CRM_Utils_Money::format($value, NULL, NULL, TRUE);
}
catch (CiviCRM_API3_Exception $e) {
* @param string $entity
* @param bool $usedForTokenWidget
*
- * @return array $customTokens
+ * @return array
* return custom field tokens in array('custom_N' => 'label') format
*/
public static function getCustomFieldTokens($entity, $usedForTokenWidget = FALSE) {