You are here

public function WebformTokenManager::buildTreeLink in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/WebformTokenManager.php \Drupal\webform\WebformTokenManager::buildTreeLink()

Build token tree link if token.module is installed.

Parameters

array $token_types: An array containing token types that should be shown in the tree.

Return value

array A render array containing a token tree link.

Overrides WebformTokenManagerInterface::buildTreeLink

File

src/WebformTokenManager.php, line 220

Class

WebformTokenManager
Defines a class to manage token replacement.

Namespace

Drupal\webform

Code

public function buildTreeLink(array $token_types = [
  'webform',
  'webform_submission',
  'webform_handler',
]) {
  if (!$this->moduleHandler
    ->moduleExists('token')) {
    return [
      '#type' => 'link',
      '#title' => $this
        ->t('You may use tokens.'),
      '#url' => Url::fromUri('https://www.drupal.org/project/token'),
    ];
  }
  else {
    return [
      '#theme' => 'token_tree_link',
      '#text' => $this
        ->t('You may use tokens.'),
      '#token_types' => $token_types,
      '#click_insert' => TRUE,
      '#dialog' => TRUE,
      '#attached' => [
        'library' => [
          'webform/webform.token',
        ],
      ],
    ];
  }
}