forked from civicrm/civicrm-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTokens.php
705 lines (670 loc) · 24.8 KB
/
Tokens.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
use Civi\Api4\Contact;
use Civi\Token\Event\TokenRegisterEvent;
use Civi\Token\Event\TokenValueEvent;
use Civi\Token\TokenProcessor;
use Civi\Token\TokenRow;
/**
* Class CRM_Contact_Tokens
*
* Generate "contact.*" tokens.
*/
class CRM_Contact_Tokens extends CRM_Core_EntityTokens {
/**
* Get the entity name for api v4 calls.
*
* @return string
*/
protected function getApiEntityName(): string {
return 'Contact';
}
/**
* @inheritDoc
*/
public static function getSubscribedEvents(): array {
return [
'civi.token.eval' => [
['evaluateLegacyHookTokens', 500],
['onEvaluate'],
],
'civi.token.list' => 'registerTokens',
];
}
/**
* Register the declared tokens.
*
* @param \Civi\Token\Event\TokenRegisterEvent $e
* The registration event. Add new tokens using register().
*
* @throws \CRM_Core_Exception
*/
public function registerTokens(TokenRegisterEvent $e): void {
if (!$this->checkActive($e->getTokenProcessor())) {
return;
}
foreach ($this->getTokenMetadata() as $tokenName => $field) {
if ($field['audience'] === 'user') {
$e->register([
'entity' => $this->entity,
// We advertise the new-style token names - but support legacy ones.
'field' => $tokenName,
'label' => $field['title'],
]);
}
}
foreach ($this->getLegacyHookTokens() as $legacyHookToken) {
$e->register([
'entity' => $legacyHookToken['category'],
'field' => $legacyHookToken['name'],
'label' => $legacyHookToken['label'],
]);
}
}
/**
* Determine whether this token-handler should be used with
* the given processor.
*
* To short-circuit token-processing in irrelevant contexts,
* override this.
*
* @param \Civi\Token\TokenProcessor $processor
* @return bool
*/
public function checkActive(TokenProcessor $processor): bool {
return in_array($this->getEntityIDField(), $processor->context['schema'], TRUE);
}
/**
* @return string
*/
protected function getEntityIDField(): string {
return 'contactId';
}
/**
* Get functions declared using the legacy hook.
*
* Note that these only extend the contact entity (
* ie they are based on having a contact ID which they.
* may or may not use, but they don't have other
* entity IDs.)
*
* @return array
*/
protected function getLegacyHookTokens(): array {
$tokens = [];
foreach ($this->getHookTokens() as $tokenValues) {
foreach ($tokenValues as $key => $value) {
if (is_numeric($key)) {
// This appears to be an attempt to compensate for
// inconsistencies described in https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_tokenValues/#example
// in effect there is a suggestion that
// Send an Email" and "CiviMail" send different parameters to the tokenValues hook
// As of now 'send an email' renders hooks through this class.
// CiviMail it depends on the use or otherwise of flexmailer.
$key = $value;
}
if (preg_match('/^\{([^\}]+)\}$/', $value, $matches)) {
$value = $matches[1];
}
$keyParts = explode('.', $key);
$tokens[$key] = [
'category' => $keyParts[0],
'name' => $keyParts[1],
'label' => $value,
];
}
}
return $tokens;
}
/**
* Get all tokens advertised as contact tokens.
*
* @return string[]
*/
protected function getExposedFields(): array {
return [
'contact_type',
'do_not_email',
'do_not_phone',
'do_not_mail',
'do_not_sms',
'do_not_trade',
'is_opt_out',
'external_identifier',
'sort_name',
'display_name',
'nick_name',
'image_URL',
'preferred_communication_method',
'preferred_language',
'hash',
'source',
'first_name',
'middle_name',
'last_name',
'prefix_id',
'suffix_id',
'formal_title',
'communication_style_id',
'job_title',
'gender_id',
'birth_date',
'deceased_date',
'employer_id',
'is_deleted',
'created_date',
'modified_date',
'addressee_display',
'email_greeting_display',
'postal_greeting_display',
'id',
];
}
/**
* Get the fields exposed from related entities.
*
* @return string[][]
*/
protected function getRelatedEntityTokenMetadata(): array {
return [
'address' => [
'location_type_id',
'id',
'street_address',
'street_number',
'street_number_suffix',
'street_name',
'street_unit',
'supplemental_address_1',
'supplemental_address_2',
'supplemental_address_3',
'city',
'postal_code_suffix',
'postal_code',
'manual_geo_code',
'geo_code_1',
'geo_code_2',
'name',
'master_id',
'county_id',
'state_province_id',
'country_id',
],
'phone' => ['phone', 'phone_ext', 'phone_type_id'],
'email' => ['email', 'signature_html', 'signature_text', 'on_hold'],
'website' => ['url'],
'openid' => ['openid'],
'im' => ['name', 'provider_id'],
];
}
/**
* Load token data from legacy hooks.
*
* While our goal is for people to move towards implementing
* toke processors the old-style hooks can extend contact
* token data.
*
* When that is happening we need to load the full contact record
* to send to the hooks (not great for performance but the
* fix is to move away from implementing legacy style hooks).
*
* Consistent with prior behaviour we only load the contact it it
* is already loaded. In that scenario we also load any extra fields
* that might be wanted for the contact tokens.
*
* @param \Civi\Token\Event\TokenValueEvent $e
*
* @throws \CRM_Core_Exception
*/
public function evaluateLegacyHookTokens(TokenValueEvent $e): void {
$messageTokens = $e->getTokenProcessor()->getMessageTokens();
if (empty($messageTokens) || !array_intersect(array_keys($this->getHookTokens()), array_keys($messageTokens))) {
return;
}
foreach ($e->getRows() as $row) {
if (empty($row->context['contactId'])) {
continue;
}
unset($swapLocale);
$swapLocale = empty($row->context['locale']) ? NULL : \CRM_Utils_AutoClean::swapLocale($row->context['locale']);
if (empty($row->context['contact'])) {
// If we don't have the contact already load it now, getting full
// details for hooks and anything the contact token resolution might
// want later.
$row->context['contact'] = $this->getContact($row->context['contactId'], $messageTokens['contact'] ?? [], TRUE);
}
$contactArray = [$row->context['contactId'] => $row->context['contact']];
\CRM_Utils_Hook::tokenValues($contactArray,
[$row->context['contactId']],
empty($row->context['mailingJobId']) ? NULL : $row->context['mailingJobId'],
$messageTokens,
$row->context['controller']
);
foreach ($this->getHookTokens() as $category => $hookToken) {
if (!empty($messageTokens[$category])) {
foreach (array_keys($hookToken) as $tokenName) {
$tokenPartOnly = str_replace($category . '.', '', $tokenName);
if (in_array($tokenPartOnly, $messageTokens[$category], TRUE)) {
$row->format('text/html')
->tokens($category, str_replace($category . '.', '', $tokenName), $contactArray[$row->context['contactId']][$tokenName] ?? ($contactArray[$row->context['contactId']][$category . '.' . $tokenName] ?? ''));
}
}
}
}
}
}
/**
* Load token data.
*
* @param \Civi\Token\Event\TokenValueEvent $e
*
* @throws TokenException
* @throws \CRM_Core_Exception
*/
public function onEvaluate(TokenValueEvent $e) {
$this->activeTokens = $e->getTokenProcessor()->getMessageTokens()['contact'] ?? [];
if (empty($this->activeTokens)) {
return;
}
foreach ($e->getRows() as $row) {
if (empty($row->context['contactId']) && empty($row->context['contact'])) {
continue;
}
unset($swapLocale);
$swapLocale = empty($row->context['locale']) ? NULL : \CRM_Utils_AutoClean::swapLocale($row->context['locale']);
if (empty($row->context['contact'])) {
$row->context['contact'] = $this->getContact($row->context['contactId'], $this->activeTokens);
}
foreach ($this->activeTokens as $token) {
if ($token === 'checksum') {
$cs = \CRM_Contact_BAO_Contact_Utils::generateChecksum($row->context['contactId'],
NULL,
NULL,
$row->context['hash'] ?? NULL
);
$row->format('text/html')
->tokens('contact', $token, "cs={$cs}");
}
elseif ($token === 'signature_html') {
$row->format('text/html')->tokens('contact', $token, html_entity_decode($this->getFieldValue($row, $token)));
}
else {
parent::evaluateToken($row, $this->entity, $token, $row->context['contact']);
}
}
}
}
/**
* Get the field value.
*
* @param \Civi\Token\TokenRow $row
* @param string $field
*
* @return string|int
* @throws \CRM_Core_Exception
*/
protected function getFieldValue(TokenRow $row, string $field) {
$entityName = 'contact';
$contact = $row->context['contact'];
if (isset($this->getDeprecatedTokens()[$field])) {
// Check the non-deprecated location first, fall back to deprecated
// this is important for the greetings because - they are weird in the query object.
$possibilities = [$this->getDeprecatedTokens()[$field], $field];
}
else {
$possibilities = [$field];
if (in_array($field, $this->getDeprecatedTokens(), TRUE)) {
$possibilities[] = array_search($field, $this->getDeprecatedTokens(), TRUE);
}
}
foreach ($possibilities as $possibility) {
if (isset($contact[$possibility])) {
return $contact[$possibility];
}
if ($this->isPseudoField($possibility)) {
// If we have a name or label field & already have the id loaded then we can
// evaluate from that rather than query again.
$split = explode(':', $possibility);
if (array_key_exists($split[0], $contact)) {
return $row->context['contact'][$possibility] = $this->getPseudoValue($split[0], $split[1], $contact[$split[0]]);
}
}
}
$contactID = $this->getFieldValue($row, 'id');
if ($contactID) {
$missingFields = array_diff_key(array_fill_keys($this->activeTokens, TRUE), $contact);
$row->context['contact'] = array_merge($this->getContact($contactID, array_keys($missingFields)), $contact);
if (isset($row->context[$entityName][$field])) {
return $row->context[$entityName][$field];
}
}
return '';
}
/**
* Get the metadata for the available fields.
*
* @return array
* @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection
*/
protected function getTokenMetadata(): array {
if (Civi::cache('metadata')->has($this->getCacheKey())) {
return Civi::cache('metadata')->get($this->getCacheKey());
}
$this->fieldMetadata = (array) civicrm_api4('Contact', 'getfields', ['checkPermissions' => FALSE], 'name');
$tokensMetadata = $this->getBespokeTokens();
foreach ($this->fieldMetadata as $field) {
$this->addFieldToTokenMetadata($tokensMetadata, $field, $this->getExposedFields());
}
foreach ($this->getRelatedEntityTokenMetadata() as $entity => $exposedFields) {
$apiEntity = ($entity === 'openid') ? 'OpenID' : ucfirst($entity);
if ($apiEntity === 'Im') {
$apiEntity = 'IM';
}
$metadata = (array) civicrm_api4($apiEntity, 'getfields', ['checkPermissions' => FALSE], 'name');
foreach ($metadata as $field) {
if ($entity === 'website') {
// It's not the primary - it's 'just one of them' - so the name is _first not _primary
$field['name'] = 'website_first.' . $field['name'];
$this->addFieldToTokenMetadata($tokensMetadata, $field, $exposedFields, 'website_first');
}
else {
$field['name'] = $entity . '_primary.' . $field['name'];
$this->addFieldToTokenMetadata($tokensMetadata, $field, $exposedFields, $entity . '_primary');
$field['label'] .= ' (' . ts('Billing') . ')';
// Set audience to sysadmin in case adding them to UI annoys people. If people ask to see this
// in the UI we could set to 'user'.
$field['audience'] = 'sysadmin';
$field['name'] = $entity . '_billing.' . $field['name'];
$this->addFieldToTokenMetadata($tokensMetadata, $field, $exposedFields, $entity . '_billing');
}
}
}
// Manually add in the abbreviated state province as that maps to
// what has traditionally been delivered.
$tokensMetadata['address_primary.state_province_id:abbr'] = $tokensMetadata['address_primary.state_province_id:label'];
$tokensMetadata['address_primary.state_province_id:abbr']['name'] = 'address_primary.state_province_id:abbr';
$tokensMetadata['address_primary.state_province_id:abbr']['audience'] = 'user';
// Hide the label for now because we are not sure if there are paths
// where legacy token resolution is in play where this could not be resolved.
$tokensMetadata['address_primary.state_province_id:label']['audience'] = 'sysadmin';
// Hide this really obscure one. Just cos it annoys me.
$tokensMetadata['address_primary.manual_geo_code:label']['audience'] = 'sysadmin';
$tokensMetadata['openid_primary.openid']['audience'] = 'sysadmin';
Civi::cache('metadata')->set($this->getCacheKey(), $tokensMetadata);
return $tokensMetadata;
}
/**
* Get the contact for the row.
*
* @param int $contactId
* @param array $requiredFields
* @param bool $getAll
*
* @return array
* @throws \CRM_Core_Exception
*/
protected function getContact(int $contactId, array $requiredFields, bool $getAll = FALSE): array {
$returnProperties = [];
if (in_array('checksum', $requiredFields, TRUE)) {
$returnProperties[] = 'hash';
}
foreach ($this->getTokenMappingsForRelatedEntities() as $oldName => $newName) {
if (in_array($oldName, $requiredFields, TRUE)) {
$returnProperties[] = $newName;
}
}
$joins = [];
$customFields = [];
foreach ($requiredFields as $field) {
$fieldSpec = $this->getMetadataForField($field);
$prefix = '';
if (isset($fieldSpec['table_name']) && $fieldSpec['table_name'] !== 'civicrm_contact') {
if ($fieldSpec['table_name'] === 'civicrm_website') {
$tableAlias = 'website_first';
$joins[$tableAlias] = $fieldSpec['entity'];
}
if ($fieldSpec['table_name'] === 'civicrm_openid') {
// We could start to deprecate this one maybe..... I've made it un-advertised.
$tableAlias = 'openid_primary';
$joins[$tableAlias] = $fieldSpec['entity'];
}
if ($fieldSpec['type'] === 'Custom') {
$customFields['custom_' . $fieldSpec['custom_field_id']] = $fieldSpec['name'];
}
}
$returnProperties[] = $prefix . $this->getMetadataForField($field)['name'];
}
if ($getAll) {
$returnProperties = array_merge(['*', 'custom.*'], $this->getDeprecatedTokens(), $this->getTokenMappingsForRelatedEntities());
}
$contactApi = Contact::get($this->checkPermissions)
->setSelect($returnProperties)->addWhere('id', '=', $contactId);
foreach ($joins as $alias => $joinEntity) {
$contactApi->addJoin($joinEntity . ' AS ' . $alias,
'LEFT',
['id', '=', $alias . '.contact_id'],
// For website the fact we use 'first' is the deduplication.
($joinEntity !== 'Website' ? [$alias . '.is_primary', '=', 1] : []));
}
$contact = $contactApi->execute()->first();
if (!$contact) {
// This is probably a test-only situation where tokens are retrieved for a
// fake contact id - check `testReplaceGreetingTokens`
return [];
}
foreach ($this->getDeprecatedTokens() as $apiv3Name => $fieldName) {
// it would be set already with the right value for a greeting token
// the query object returns the db value for email_greeting_display
// and a numeric value for email_greeting if you put email_greeting
// in the return properties.
if (!isset($contact[$apiv3Name]) && array_key_exists($fieldName, $contact)) {
$contact[$apiv3Name] = $contact[$fieldName];
}
}
foreach ($this->getTokenMappingsForRelatedEntities() as $oldName => $newName) {
if (isset($contact[$newName])) {
$contact[$oldName] = $contact[$newName];
}
}
//update value of custom field token
foreach ($customFields as $apiv3Name => $fieldName) {
$value = $contact[$fieldName];
if ($this->getMetadataForField($apiv3Name)['data_type'] === 'Boolean') {
$value = (int) $value;
}
$contact[$apiv3Name] = \CRM_Core_BAO_CustomField::displayValue($value, \CRM_Core_BAO_CustomField::getKeyID($apiv3Name));
}
return $contact;
}
/**
* These tokens still work but we don't advertise them.
*
* We can remove from the following places
* - scheduled reminders
* - add to 'blocked' on pdf letter & email
*
* & then at some point start issuing warnings for them
* but contact tokens are pretty central so it might be
* a bit drawn out.
*
* @return string[]
* Keys are deprecated tokens and values are their replacements.
*/
protected function getDeprecatedTokens(): array {
return [
'individual_prefix' => 'prefix_id:label',
'individual_suffix' => 'suffix_id:label',
'contact_type' => 'contact_type:label',
'gender' => 'gender_id:label',
'communication_style' => 'communication_style_id:label',
'preferred_communication_method' => 'preferred_communication_method:label',
'email_greeting' => 'email_greeting_display',
'postal_greeting' => 'postal_greeting_display',
'addressee' => 'addressee_display',
'contact_id' => 'id',
'contact_source' => 'source',
'contact_is_deleted' => 'is_deleted',
'current_employer_id' => 'employer_id',
];
}
/**
* Get the tokens that are accessed by joining onto a related entity.
*
* This is an array of legacy style tokens mapped to the new style - so that
* discontinued tokens still work (although they are no longer advertised).
*
* There are three types of legacy tokens
* - apiv3 style - e.g {contact.email}
* - ad hoc - hey cos it's CiviCRM
* - 'wrong' apiv4 style - ie I thought we would do 'primary_address' but we did
* 'address_primary' - these were added as the 'real token names' but not
* advertised & likely never adopted so handling them for a while is a
* conservative approach.
*
* The new type maps to the v4 api.
*
* @return string[]
*/
protected function getTokenMappingsForRelatedEntities(): array {
$legacyFieldMapping = [
'on_hold' => 'email_primary.on_hold:label',
'phone_type_id' => 'phone_primary.phone_type_id',
'phone_type_id:label' => 'phone_primary.phone_type_id:label',
'phone_type' => 'phone_primary.phone_type_id:label',
'phone' => 'phone_primary.phone',
'primary_phone.phone' => 'phone_primary.phone',
'phone_ext' => 'phone_primary.phone_ext',
'primary_phone.phone_ext' => 'phone_primary.phone_ext',
'current_employer' => 'employer_id.display_name',
'location_type_id' => 'address_primary.location_type_id',
'location_type' => 'address_primary.location_type_id:label',
'location_type_id:label' => 'address_primary.location_type_id:label',
'street_address' => 'address_primary.street_address',
'address_id' => 'address_primary.id',
'address_name' => 'address_primary.name',
'street_number' => 'address_primary.street_number',
'street_number_suffix' => 'address_primary.street_number_suffix',
'street_name' => 'address_primary.street_name',
'street_unit' => 'address_primary.street_unit',
'supplemental_address_1' => 'address_primary.supplemental_address_1',
'supplemental_address_2' => 'address_primary.supplemental_address_2',
'supplemental_address_3' => 'address_primary.supplemental_address_3',
'city' => 'address_primary.city',
'postal_code' => 'address_primary.postal_code',
'postal_code_suffix' => 'address_primary.postal_code_suffix',
'geo_code_1' => 'address_primary.geo_code_1',
'geo_code_2' => 'address_primary.geo_code_2',
'manual_geo_code' => 'address_primary.manual_geo_code',
'master_id' => 'address_primary.master_id',
'county' => 'address_primary.county_id:label',
'county_id' => 'address_primary.county_id',
'state_province' => 'address_primary.state_province_id:abbr',
'state_province_id' => 'address_primary.state_province_id',
'country' => 'address_primary.country_id:label',
'country_id' => 'address_primary.country_id',
'world_region' => 'address_primary.country_id.region_id:name',
'email' => 'email_primary.email',
'signature_text' => 'email_primary.signature_text',
'signature_html' => 'email_primary.signature_html',
'im' => 'im_primary.name',
'im_provider' => 'im_primary.provider_id:label',
'openid' => 'openid_primary.openid',
'url' => 'website_first.url',
];
foreach ($legacyFieldMapping as $fieldName) {
// Add in our briefly-used 'primary_address' variants.
// ie add 'primary_email.email' => 'email_primary.email'
// so allow the former to be mapped to the latter.
// We can deprecate these out later as they were likely never adopted.
$oldPrimaryName = str_replace(
['email_primary', 'im_primary', 'phone_primary', 'address_primary', 'openid_primary', 'website_first'],
['primary_email', 'primary_im', 'primary_phone', 'primary_address', 'primary_openid', 'primary_website'],
$fieldName);
if ($oldPrimaryName !== $fieldName) {
$legacyFieldMapping[$oldPrimaryName] = $fieldName;
}
}
return $legacyFieldMapping;
}
/**
* Get calculated or otherwise 'special', tokens.
*
* @return array[]
*/
protected function getBespokeTokens(): array {
return [
'checksum' => [
'title' => ts('Checksum'),
'name' => 'checksum',
'type' => 'calculated',
'options' => NULL,
'data_type' => 'String',
'input_type' => NULL,
'audience' => 'user',
],
'employer_id.display_name' => [
'title' => ts('Current Employer'),
'name' => 'employer_id.display_name',
'type' => 'mapped',
'api_v3' => 'current_employer',
'options' => NULL,
'data_type' => 'String',
'audience' => 'user',
],
'address_primary.country_id.region_id:name' => [
'title' => ts('World Region'),
'name' => 'address_primary.country_id.region_id:name',
'type' => 'mapped',
'api_v3' => 'world_region',
'options' => NULL,
'data_type' => 'String',
'input_type' => 'Text',
'advertised_name' => 'world_region',
'audience' => 'user',
],
// this gets forced out if we specify individual fields
'organization_name' => [
'title' => ts('Organization name'),
'name' => 'organization_name',
'type' => 'Field',
'options' => NULL,
'data_type' => 'String',
'input_type' => 'Text',
'audience' => 'sysadmin',
],
// this gets forced out if we specify individual fields
'household_name' => [
'title' => ts('Household name'),
'name' => 'household_name',
'type' => 'Field',
'options' => NULL,
'data_type' => 'String',
'input_type' => 'Text',
'audience' => 'sysadmin',
],
];
}
/**
* Get the tokens defined by the legacy hook.
*
* @return array
*/
protected function getHookTokens(): array {
if (isset(Civi::$statics[__CLASS__]['hook_tokens'])) {
return Civi::$statics[__CLASS__]['hook_tokens'];
}
$tokens = [];
\CRM_Utils_Hook::tokens($tokens);
Civi::$statics[__CLASS__]['hook_tokens'] = $tokens;
return $tokens;
}
}