* regular expression sutiable for using in preg_replace
*/
private static function tokenRegex($token_type) {
- return '/(?<!\{|\\\\)\{' . $token_type . '\.([\w]+(\-[\w\s]+)?)\}(?!\})/';
+ return '/(?<!\{|\\\\)\{' . $token_type . '\.([\w]+:?\w*(\-[\w\s]+)?)\}(?!\})/';
}
/**
public static function getTokens($string) {
$matches = [];
$tokens = [];
- preg_match_all('/(?<!\{|\\\\)\{(\w+\.\w+)\}(?!\})/',
+ preg_match_all('/(?<!\{|\\\\)\{(\w+\.\w+:?\w*)\}(?!\})/',
$string,
$matches,
PREG_PATTERN_ORDER
protected static function _buildContributionTokens() {
$key = 'contribution';
- if (self::$_tokens[$key] == NULL) {
- self::$_tokens[$key] = array_keys(array_merge(CRM_Contribute_BAO_Contribution::exportableFields('All'),
- ['campaign', 'financial_type'],
- self::getCustomFieldTokens('Contribution')
- ));
+
+ if (!isset(Civi::$statics[__CLASS__][__FUNCTION__][$key])) {
+ $processor = new CRM_Contribute_Tokens();
+ $tokens = array_merge(CRM_Contribute_BAO_Contribution::exportableFields('All'),
+ ['campaign' => [], 'financial_type' => [], 'payment_instrument' => []],
+ self::getCustomFieldTokens('Contribution'),
+ $processor->getPseudoTokens()
+ );
+ foreach ($tokens as $token) {
+ if (!empty($token['name'])) {
+ $tokens[$token['name']] = [];
+ }
+ }
+ Civi::$statics[__CLASS__][__FUNCTION__][$key] = array_keys($tokens);
}
+ self::$_tokens[$key] = Civi::$statics[__CLASS__][__FUNCTION__][$key];
}
/**
//early return
return $str;
}
- self::_buildContributionTokens();
// here we intersect with the list of pre-configured valid tokens
// so that we remove anything we do not recognize
return $value;
}
+ /**
+ * Get token deprecation information.
+ *
+ * @return array
+ */
+ public static function getTokenDeprecations(): array {
+ return [
+ 'WorkFlowMessageTemplates' => [
+ 'contribution_invoice_receipt' => [
+ '$display_name' => 'contact.display_name',
+ ],
+ ],
+ ];
+ }
+
}