Merge pull request #21103 from mlutfy/ui38
[civicrm-core.git] / CRM / Contribute / Tokens.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
6 | |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
11 */
12
13 /**
14 * Class CRM_Contribute_Tokens
15 *
16 * Generate "contribution.*" tokens.
17 *
18 * At time of writing, we don't have any particularly special tokens -- we just
19 * do some basic formatting based on the corresponding DB field.
20 */
21 class CRM_Contribute_Tokens extends CRM_Core_EntityTokens {
22
23 /**
24 * @return string
25 */
26 protected function getEntityName(): string {
27 return 'contribution';
28 }
29
30 /**
31 * @return string
32 */
33 protected function getEntityAlias(): string {
34 return 'contrib_';
35 }
36
37 /**
38 * Get the entity name for api v4 calls.
39 *
40 * In practice this IS just ucfirst($this->GetEntityName)
41 * but declaring it seems more legible.
42 *
43 * @return string
44 */
45 protected function getApiEntityName(): string {
46 return 'Contribution';
47 }
48
49 /**
50 * Get a list of tokens for the entity for which access is permitted to.
51 *
52 * This list is historical and we need to question whether we
53 * should filter out any fields (other than those fields, like api_key
54 * on the contact entity) with permissions defined.
55 *
56 * @return array
57 */
58 protected function getExposedFields(): array {
59 $fields = [
60 'contribution_page_id',
61 'source',
62 'id',
63 'receive_date',
64 'total_amount',
65 'fee_amount',
66 'net_amount',
67 'non_deductible_amount',
68 'trxn_id',
69 'invoice_id',
70 'currency',
71 'cancel_date',
72 'receipt_date',
73 'thankyou_date',
74 'tax_amount',
75 'contribution_status_id',
76 'financial_type_id',
77 'payment_instrument_id',
78 'cancel_reason',
79 'amount_level',
80 'check_number',
81 ];
82 if (CRM_Campaign_BAO_Campaign::isCampaignEnable()) {
83 $fields[] = 'campaign_id';
84 }
85 return $fields;
86 }
87
88 /**
89 * Get tokens supporting the syntax we are migrating to.
90 *
91 * In general these are tokens that were not previously supported
92 * so we can add them in the preferred way or that we have
93 * undertaken some, as yet to be written, db update.
94 *
95 * See https://lab.civicrm.org/dev/core/-/issues/2650
96 *
97 * @return string[]
98 */
99 public function getBasicTokens(): array {
100 $return = [];
101 foreach ($this->getExposedFields() as $fieldName) {
102 $return[$fieldName] = $this->getFieldMetadata()[$fieldName]['title'];
103 }
104 return $return;
105 }
106
107 }