public function WebformTokenManager::buildTreeElement in Webform 6.x
Same name and namespace in other branches
- 8.5 src/WebformTokenManager.php \Drupal\webform\WebformTokenManager::buildTreeElement()
Build token tree element if token.module is installed.
Parameters
array $token_types: An array containing token types that should be shown in the tree.
string $description: (optional) Description to appear after the token tree link.
Return value
array A render array containing a token tree link wrapped in a div.
Overrides WebformTokenManagerInterface::buildTreeElement
File
- src/
WebformTokenManager.php, line 243
Class
- WebformTokenManager
- Defines a class to manage token replacement.
Namespace
Drupal\webformCode
public function buildTreeElement(array $token_types = [
'webform',
'webform_submission',
'webform_handler',
], $description = NULL) {
if (!$this->moduleHandler
->moduleExists('token')) {
return [];
}
$build = [
'#theme' => 'token_tree_link',
'#token_types' => $token_types,
'#click_insert' => TRUE,
'#dialog' => TRUE,
'#attached' => [
'library' => [
'webform/webform.token',
],
],
];
if ($description) {
if ($this->config
->get('ui.description_help')) {
return [
'#type' => 'container',
'token_tree_link' => $build,
'help' => [
'#type' => 'webform_help',
'#help' => $description,
],
];
}
else {
return [
'#type' => 'container',
'token_tree_link' => $build,
'description' => [
'#prefix' => ' ',
'#markup' => $description,
],
];
}
}
else {
return [
'#type' => 'container',
'token_tree_link' => $build,
];
}
}