function flag_lists_tokens in Flag Lists 8
Same name and namespace in other branches
- 7.3 flag_lists.module \flag_lists_tokens()
- 7 flag_lists.module \flag_lists_tokens()
- 4.0.x flag_lists.tokens.inc \flag_lists_tokens()
Implements hook_tokens().
File
- ./
flag_lists.tokens.inc, line 46 - Flag lists module tokens support.
Code
function flag_lists_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
$tokenService = \Drupal::token();
$url_options = [
'absolute' => TRUE,
];
if (isset($options['langcode'])) {
$url_options['language'] = \Drupal::languageManager()
->getLanguage($options['langcode']);
$langcode = $options['langcode'];
}
else {
$langcode = NULL;
}
$replacements = [];
if ($type == 'flagging_collection' && !empty($data['flagging_collection'])) {
/** @var \Drupal\flag_lists\Entity\FlaggingCollection $flc */
$flc = $data['flagging_collection'];
foreach ($tokens as $name => $original) {
switch ($name) {
// Simple key values on the node.
case 'id':
$replacements[$original] = $flc
->id();
break;
case 'name':
$replacements[$original] = $flc
->getName();
break;
}
}
}
return $replacements;
}