function organigrams_tokens in Organigrams 8
Same name and namespace in other branches
- 8.2 organigrams.module \organigrams_tokens()
- 7 organigrams.module \organigrams_tokens()
Implements hook_tokens().
Add content to the organigrams tokens.
File
- ./
organigrams.module, line 267 - Extends Taxonomy to create organigrams.
Code
function organigrams_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
$replacements = [];
// Check if the type is organigrams.
if ($type == 'organigrams') {
// Iterate through the tokens.
foreach ($tokens as $name => $original) {
// Load the vocabulary.
$vocabulary = \Drupal::entityTypeManager()
->getStorage('taxonomy_vocabulary')
->load($name);
// Load the taxonomy term tree service.
$taxonomyTermTree = \Drupal::getContainer()
->get('organigrams.taxonomy_term_tree');
// Create the organigram.
$organigramsController = new OrganigramsController($taxonomyTermTree);
$organigram = $organigramsController
->viewOrganigram($vocabulary);
// Put the organigram as value in this token.
$replacements[$original] = render($organigram);
}
}
return $replacements;
}