+--------------------------------------------------------------------+
*/
-use Civi\ActionSchedule\Event\MailingQueryEvent;
-use Civi\Token\TokenProcessor;
-use Civi\Token\TokenRow;
-
/**
* Class CRM_Contribute_Tokens
*
return 'Contribution';
}
- /**
- * Metadata about the entity fields.
- *
- * @var array
- */
- protected $fieldMetadata = [];
-
/**
* Get a list of tokens for the entity for which access is permitted to.
*
* @return array
*/
protected function getExposedFields(): array {
- return [
+ $fields = [
'contribution_page_id',
'source',
'id',
'contribution_status_id',
'financial_type_id',
'payment_instrument_id',
+ 'cancel_reason',
+ 'amount_level',
+ 'check_number',
];
+ if (CRM_Campaign_BAO_Campaign::isCampaignEnable()) {
+ $fields[] = 'campaign_id';
+ }
+ return $fields;
}
/**
return $return;
}
- /**
- * Class constructor.
- */
- public function __construct() {
- $tokens = $this->getAllTokens();
- parent::__construct('contribution', $tokens);
- }
-
- /**
- * Check if the token processor is active.
- *
- * @param \Civi\Token\TokenProcessor $processor
- *
- * @return bool
- */
- public function checkActive(TokenProcessor $processor) {
- return !empty($processor->context['actionMapping'])
- && $processor->context['actionMapping']->getEntity() === $this->getExtendableTableName();
- }
-
- /**
- * Alter action schedule query.
- *
- * @param \Civi\ActionSchedule\Event\MailingQueryEvent $e
- */
- public function alterActionScheduleQuery(MailingQueryEvent $e): void {
- if ($e->mapping->getEntity() !== $this->getExtendableTableName()) {
- return;
- }
- foreach ($this->getReturnFields() as $token) {
- $e->query->select('e.' . $token . ' AS ' . $this->getEntityAlias() . $token);
- }
- }
-
- /**
- * @inheritDoc
- * @throws \CRM_Core_Exception
- */
- public function evaluateToken(TokenRow $row, $entity, $field, $prefetch = NULL) {
- $fieldValue = $this->getFieldValue($row, $field);
-
- if ($this->isPseudoField($field)) {
- $split = explode(':', $field);
- return $row->tokens($entity, $field, $this->getPseudoValue($split[0], $split[1], $this->getFieldValue($row, $split[0])));
- }
- if ($this->isMoneyField($field)) {
- return $row->format('text/plain')->tokens($entity, $field,
- \CRM_Utils_Money::format($fieldValue, $this->getFieldValue($row, 'currency')));
- }
- if ($this->isDateField($field)) {
- return $row->format('text/plain')->tokens($entity, $field, \CRM_Utils_Date::customFormat($fieldValue));
- }
- if ($this->isCustomField($field)) {
- $row->customToken($entity, \CRM_Core_BAO_CustomField::getKeyID($field), $this->getFieldValue($row, 'id'));
- }
- else {
- $row->format('text/plain')->tokens($entity, $field, (string) $fieldValue);
- }
- }
-
}