$value = NULL;
+ // Support legacy tokens
+ $token = CRM_Utils_Array::value($token, self::legacyContactTokens(), $token);
+
// check if the token we were passed is valid
// we have to do this because this function is
// called only when we find a token in the string
else {
$value = CRM_Utils_Array::retrieveValueRecursive($contact, $token);
- // note that incase of pseudoconstants we get array ( 0 => id, 1 => label )
+ // FIXME: for some pseudoconstants we get array ( 0 => id, 1 => label )
if (is_array($value)) {
$value = $value[1];
}
+ // Convert pseudoconstants using metadata
+ elseif ($value && is_numeric($value)) {
+ $allFields = CRM_Contact_BAO_Contact::exportableFields('All');
+ if (!empty($allFields[$token]['pseudoconstant'])) {
+ $value = CRM_Core_PseudoConstant::getLabel('CRM_Contact_BAO_Contact', $token, $value);
+ }
+ }
}
if (!$html) {
* @param array $membershipIDs array of membership IDS
*/
static function getMembershipTokenDetails($membershipIDs) {
- $memberships = civicrm_api3('membership', 'get', array('membership_id' => array('IN' => (array) $membershipIDs)));
+ $memberships = civicrm_api3('membership', 'get', array('options' => array('limit' => 200000), 'membership_id' => array('IN' => (array) $membershipIDs)));
return $memberships['values'];
}
/**
if (!empty($greetingTokens)) {
// first use the existing contact object for token replacement
if (!empty($contactDetails)) {
- // unset id's to get labels for the pseudoconstants
- foreach ( array('individual_prefix', 'individual_suffix', 'gender') as $field ) {
- unset($contactDetails[0][$contactId][$field]);
- }
$tokenString = CRM_Utils_Token::replaceContactTokens($tokenString, $contactDetails, TRUE, $greetingTokens, TRUE);
}
function getPermissionEmails($permissionName) {}
function getRoleEmails($roleName) {}
+
+ /**
+ * @return array: legacy_token => new_token
+ */
+ static function legacyContactTokens() {
+ return array(
+ 'individual_prefix' => 'prefix_id',
+ 'individual_suffix' => 'suffix_id',
+ 'gender' => 'gender_id',
+ );
+ }
+
}