- Issue created by @trichers
- πΊπΈUnited States pixiekat
You'll want to look at hook_tokens and hook_token_info.
Those will let you define the tokens and define the token replacements.
- πΊπΈUnited States owenbush Denver, CO
There is also a patch you could apply which exposes all custom entity fields as tokens. If what you want to create a token for is a registrant field itself and not something custom then take a look at
β¨ Consistent tokens support across all entities and fields Needs work
- π©πͺGermany trichers
@pixiekat Thank you, it worked:
function MY_MODULE_token_info() { $registrant = []; $registrant['id'] = [ 'name' => t('Registrant ID'), 'description' => t('Get the ID of the registrant.'), ]; $registrant['uuid'] = [ 'name' => t('Registrant UUID'), 'description' => t('Get the UUID of the registrant.'), ]; return $registrant; } function MY_MODULE_tokens($type, $tokens, array $data, array $options, \Drupal\Core\Render\BubbleableMetadata $bubbleable_metadata) { $replacements = []; $registrant = !empty($data['registrant']) ? $data['registrant'] : NULL; if ($type == 'registrant' && !empty($data['registrant'])) { foreach ($tokens as $name => $original) { switch ($name) { case 'id': $replacements[$original] = $registrant->id->value; break; case 'uuid': $replacements[$original] = $registrant->uuid->value; break; } } } return $replacements; }
- Status changed to Fixed
11 months ago 3:59pm 17 December 2023 - Status changed to Fixed
11 months ago 4:00pm 17 December 2023