Skip to content
Snippets Groups Projects
Unverified Commit 49bcd488 authored by colemanw's avatar colemanw Committed by GitHub
Browse files

Merge pull request #21039 from eileenmcnaughton/tok_pseudo

Reconcile tokens misnamed or missing on legacy class
parents 60738cf9 4a526c1b
Branches
Tags
No related merge requests found
......@@ -58,10 +58,15 @@ class CRM_Contribute_Tokens extends CRM_Core_EntityTokens {
protected $fieldMetadata = [];
/**
* Get a list of tokens whose name and title match the DB fields.
* 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 getPassthruTokens(): array {
protected function getExposedFields(): array {
return [
'contribution_page_id',
'source',
......@@ -97,7 +102,7 @@ class CRM_Contribute_Tokens extends CRM_Core_EntityTokens {
*/
public function getBasicTokens(): array {
$return = [];
foreach (['contribution_status_id', 'payment_instrument_id', 'financial_type_id', 'contribution_page_id'] as $fieldName) {
foreach ($this->getExposedFields() as $fieldName) {
$return[$fieldName] = $this->getFieldMetadata()[$fieldName]['title'];
}
return $return;
......@@ -107,11 +112,7 @@ class CRM_Contribute_Tokens extends CRM_Core_EntityTokens {
* Class constructor.
*/
public function __construct() {
$tokens = CRM_Utils_Array::subset(
CRM_Utils_Array::collect('title', $this->getFieldMetadata()),
$this->getPassthruTokens()
);
$tokens = array_merge($tokens, $this->getPseudoTokens(), CRM_Utils_Token::getCustomFieldTokens('Contribution'));
$tokens = $this->getAllTokens();
parent::__construct('contribution', $tokens);
}
......@@ -138,7 +139,7 @@ class CRM_Contribute_Tokens extends CRM_Core_EntityTokens {
}
$fields = $this->getFieldMetadata();
foreach ($this->getPassthruTokens() as $token) {
foreach (array_keys($this->getBasicTokens()) as $token) {
$e->query->select('e.' . $fields[$token]['name'] . ' AS ' . $this->getEntityAlias() . $token);
}
foreach (array_keys($this->getPseudoTokens()) as $token) {
......
......@@ -61,6 +61,15 @@ class CRM_Core_EntityTokens extends AbstractTokenSubscriber {
return CRM_Core_DAO_AllCoreTables::getFullName($this->getApiEntityName());
}
/**
* Get all the tokens supported by this processor.
*
* @return array|string[]
*/
public function getAllTokens(): array {
return array_merge($this->getBasicTokens(), $this->getPseudoTokens(), CRM_Utils_Token::getCustomFieldTokens('Contribution'));
}
/**
* Is the given field a date field.
*
......
......@@ -565,27 +565,16 @@ class CRM_Core_SelectValues {
public static function contributionTokens(): array {
$tokens = [];
$processor = new CRM_Contribute_Tokens();
foreach (array_merge($processor->getPseudoTokens(), $processor->getBasicTokens()) as $token => $title) {
foreach ($processor->getAllTokens() as $token => $title) {
$tokens['{contribution.' . $token . '}'] = $title;
}
return array_merge($tokens, [
'{contribution.id}' => ts('Contribution ID'),
'{contribution.total_amount}' => ts('Total Amount'),
'{contribution.fee_amount}' => ts('Fee Amount'),
'{contribution.net_amount}' => ts('Net Amount'),
'{contribution.non_deductible_amount}' => ts('Non-deductible Amount'),
'{contribution.receive_date}' => ts('Contribution Date Received'),
'{contribution.trxn_id}' => ts('Transaction ID'),
'{contribution.invoice_id}' => ts('Invoice ID'),
'{contribution.currency}' => ts('Currency'),
'{contribution.cancel_date}' => ts('Contribution Cancel Date'),
'{contribution.cancel_reason}' => ts('Contribution Cancel Reason'),
'{contribution.receipt_date}' => ts('Receipt Date'),
'{contribution.thankyou_date}' => ts('Thank You Date'),
'{contribution.source}' => ts('Contribution Source'),
'{contribution.amount_level}' => ts('Amount Level'),
'{contribution.check_number}' => ts('Check Number'),
'{contribution.campaign}' => ts('Contribution Campaign'),
// @todo - we shouldn't need to include custom fields here -
// remove, with test.
], CRM_Utils_Token::getCustomFieldTokens('Contribution', TRUE));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment