* @return array|string[]
*/
public function getAllTokens(): array {
- return array_merge($this->getBasicTokens(), $this->getPseudoTokens(), CRM_Utils_Token::getCustomFieldTokens($this->getApiEntityName()));
+ $basicTokens = $this->getBasicTokens();
+ foreach (array_keys($basicTokens) as $fieldName) {
+ // The goal is to be able to render more complete tokens
+ // (eg. actual booleans, field names, raw ids) for a more
+ // advanced audiences - ie those using conditionals
+ // and to specify that audience in the api that retrieves.
+ // But, for now, let's not advertise, given that most of these fields
+ // aren't really needed even once...
+ if ($this->isBooleanField($fieldName)) {
+ unset($basicTokens[$fieldName]);
+ }
+ }
+ return array_merge($basicTokens, $this->getPseudoTokens(), CRM_Utils_Token::getCustomFieldTokens($this->getApiEntityName()));
+ }
+
+ /**
+ * Is the given field a boolean field.
+ *
+ * @param string $fieldName
+ *
+ * @return bool
+ */
+ public function isBooleanField(string $fieldName): bool {
+ return $this->getFieldMetadata()[$fieldName]['data_type'] === 'Boolean';
}
/**
$return[$fieldName . ':label'] = $fieldLabel;
$return[$fieldName . ':name'] = ts('Machine name') . ': ' . $fieldLabel;
}
+ if ($this->isBooleanField($fieldName)) {
+ $return[$fieldName . ':label'] = $this->getFieldMetadata()[$fieldName]['title'];
+ }
}
return $return;
}
$fields = (array) Contribution::getFields()->addSelect('name', 'title')->execute()->indexBy('name');
$allFields = [];
foreach ($fields as $field) {
- $allFields[$field['name']] = $field['title'];
+ if (!in_array($field['name'], ['is_test', 'is_pay_later', 'is_template'], TRUE)) {
+ $allFields[$field['name']] = $field['title'];
+ }
}
// contact ID is skipped.
unset($allFields['contact_id']);
'trxn_id' => 'Transaction ID',
'invoice_id' => 'Invoice ID',
'contribution_status_id' => 'Status',
- 'is_test' => 'Test',
+ 'is_test:label' => 'Test',
'cycle_day' => 'Cycle Day',
'next_sched_contribution_date' => 'Next Scheduled Contribution Date',
'failure_count' => 'Number of Failures',
'failure_retry_date' => 'Retry Failed Attempt Date',
- 'auto_renew' => 'Auto Renew',
+ 'auto_renew:label' => 'Auto Renew',
'payment_processor_id' => 'Payment Processor ID',
'financial_type_id' => 'Financial Type ID',
'payment_instrument_id' => 'Payment Method',
- 'is_email_receipt' => 'Send email Receipt?',
+ 'is_email_receipt:label' => 'Send email Receipt?',
'frequency_unit:label' => 'Frequency Unit',
'frequency_unit:name' => 'Machine name: Frequency Unit',
'contribution_status_id:label' => 'Status',
123
inv123
2
-1
+Yes
15
0
January 3rd, 2020 12:00 AM
-1
+Yes
1
2
4
-1
+Yes
year
year
Pending Label**
Pending
-Dummy
-Dummy
+Dummy (test)
+Dummy (test)
Member Dues
Member Dues
Check