-
Notifications
You must be signed in to change notification settings - Fork 0
Add tokens
Willi edited this page Apr 10, 2018
·
1 revision
my_module.tokens.inc
/**
* Implements hook_token_info().
*/
function my_module_token_info() {
// Token types.
$tokens['tokens']['<sub>']['<token>'] = [
'name' => t("<token_name>"),
'description' => t("<token_description>"),
'type' => 'url',
];
return $tokens;
}
/**
* Implements hook_tokens().
*/
function my_module_tokens($type, $tokens, array $data = [], array $options = []) {
$replacements = [];
$url_options = array('absolute' => TRUE);
if (isset($options['langcode'])) {
$url_options['language'] = \Drupal::languageManager()->getLanguage($options['langcode']);
$langcode = $options['langcode'];
}
else {
$langcode = NULL;
}
foreach ($tokens as $name => $original) {
switch ($name) {
case '<token>':
$token = <replacement_text>;
$replacements[$original] = $token
break;
}
}
return $replacements;
}
- Drupal
- Theming
- Drush
- Updates
- GIT