X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContribute%2FTokens.php;h=6569c6a72ee34146048117db326b0e4ba7be8f54;hb=74b824c6bd3f7b29ffedb4dbbec424bac37e5c72;hp=4f56ab63430556a1ea67345bd7f74210e3836540;hpb=de24d8f394cfc1d38be4698376e1df770f713a51;p=civicrm-core.git diff --git a/CRM/Contribute/Tokens.php b/CRM/Contribute/Tokens.php index 4f56ab6343..6569c6a72e 100644 --- a/CRM/Contribute/Tokens.php +++ b/CRM/Contribute/Tokens.php @@ -10,10 +10,6 @@ +--------------------------------------------------------------------+ */ -use Civi\ActionSchedule\Event\MailingQueryEvent; -use Civi\Token\TokenProcessor; -use Civi\Token\TokenRow; - /** * Class CRM_Contribute_Tokens * @@ -24,13 +20,6 @@ use Civi\Token\TokenRow; */ class CRM_Contribute_Tokens extends CRM_Core_EntityTokens { - /** - * @return string - */ - protected function getEntityName(): string { - return 'contribution'; - } - /** * @return string */ @@ -51,123 +40,10 @@ class CRM_Contribute_Tokens extends CRM_Core_EntityTokens { } /** - * Metadata about the entity fields. - * - * @var array - */ - protected $fieldMetadata = []; - - /** - * Get a list of tokens for the entity for which access is permitted to. - * - * This list is historical and we need to question whether we - * should filter out any fields (other than those fields, like api_key - * on the contact entity) with permissions defined. - * * @return array */ - protected function getExposedFields(): array { - return [ - 'contribution_page_id', - 'source', - 'id', - 'receive_date', - 'total_amount', - 'fee_amount', - 'net_amount', - 'non_deductible_amount', - 'trxn_id', - 'invoice_id', - 'currency', - 'cancel_date', - 'receipt_date', - 'thankyou_date', - 'tax_amount', - 'contribution_status_id', - 'financial_type_id', - 'payment_instrument_id', - ]; - } - - /** - * Get tokens supporting the syntax we are migrating to. - * - * In general these are tokens that were not previously supported - * so we can add them in the preferred way or that we have - * undertaken some, as yet to be written, db update. - * - * See https://lab.civicrm.org/dev/core/-/issues/2650 - * - * @return string[] - */ - public function getBasicTokens(): array { - $return = []; - foreach ($this->getExposedFields() as $fieldName) { - $return[$fieldName] = $this->getFieldMetadata()[$fieldName]['title']; - } - 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) { - $actionSearchResult = $row->context['actionSearchResult']; - $aliasedField = $this->getEntityAlias() . $field; - $fieldValue = $actionSearchResult->{$aliasedField} ?? NULL; - - if ($this->isPseudoField($field)) { - $split = explode(':', $field); - return $row->tokens($entity, $field, $this->getPseudoValue($split[0], $split[1], $actionSearchResult->{"contrib_$split[0]"} ?? NULL)); - } - if ($this->isMoneyField($field)) { - return $row->format('text/plain')->tokens($entity, $field, - \CRM_Utils_Money::format($fieldValue, $actionSearchResult->contrib_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), $actionSearchResult->entity_id); - } - else { - $row->format('text/plain')->tokens($entity, $field, (string) $fieldValue); - } + public function getCurrencyFieldName() { + return ['currency']; } }