You are here

protected function ItemForm::getTokensLink in Business Rules 8

Same name and namespace in other branches
  1. 2.x src/Form/ItemForm.php \Drupal\business_rules\Form\ItemForm::getTokensLink()

Provide a link a modal window with all available tokens.

Return value

\Drupal\Core\GeneratedLink|null The modal link or NULL if Token module is not installed.

1 call to ItemForm::getTokensLink()
ItemForm::form in src/Form/ItemForm.php
Gets the actual form array to be built.

File

src/Form/ItemForm.php, line 329

Class

ItemForm
Base class for Business rules item.

Namespace

Drupal\business_rules\Form

Code

protected function getTokensLink() {
  if ($this->util->moduleHandler
    ->moduleExists('token')) {

    // Show a link to a modal window with all available tokens.
    $keyvalue = $this->util
      ->getKeyValueExpirable('token_tree');
    $content = $this->util->tokenTree
      ->buildAllRenderable();
    $keyvalue
      ->set('token_tree', $content);
    $tokens_link = Link::createFromRoute($this
      ->t('Click here to see all available tokens. Be aware that some tokens will only works on the right context.'), 'business_rules.ajax.modal', [
      'method' => 'nojs',
      'title' => $this
        ->t('Tokens'),
      'collection' => 'token_tree',
      'key' => 'token_tree',
    ], [
      'attributes' => [
        'class' => [
          'use-ajax',
        ],
      ],
    ])
      ->toString();
    return $tokens_link;
  }
  else {
    return NULL;
  }
}