private function DomainTokenBlock::renderTokens in Domain Access 8
Generates available tokens for printing.
Parameters
\Drupal\domain\DomainInterface $domain: The active domain request.
Return value
array An array keyed by token name, with value of replacement value.
1 call to DomainTokenBlock::renderTokens()
- DomainTokenBlock::build in domain/
src/ Plugin/ Block/ DomainTokenBlock.php - Build the output.
File
- domain/
src/ Plugin/ Block/ DomainTokenBlock.php, line 55
Class
- DomainTokenBlock
- Provides a token information block for a domain request.
Namespace
Drupal\domain\Plugin\BlockCode
private function renderTokens(DomainInterface $domain) {
$rows = [];
$token = \Drupal::token();
$tokens = $token
->getInfo();
// The 'domain' token is supported by core. The others by Token module,
// so we cannot assume that Token module is present.
$domain_tokens = [
'domain',
'current-domain',
'default-domain',
];
foreach ($domain_tokens as $key) {
if (isset($tokens['tokens'][$key])) {
$data = [];
// Pass domain data to the default handler.
if ($key == 'domain') {
$data['domain'] = $domain;
}
foreach ($tokens['tokens'][$key] as $name => $info) {
$string = "[{$key}:{$name}]";
$rows[] = [
$string,
$token
->replace($string, $data),
];
}
}
}
return $rows;
}