You are here

protected function Email::getAvailableTokensList in Search API Saved Searches 8

Provides an overview of available tokens.

Parameters

string[] $types: The token types for which to list tokens.

Return value

array A form/render element for displaying the available tokens for the given types.

1 call to Email::getAvailableTokensList()
Email::buildConfigurationForm in src/Plugin/search_api_saved_searches/notification/Email.php
Form constructor.

File

src/Plugin/search_api_saved_searches/notification/Email.php, line 292

Class

Email
Provides e-mails as a notification mechanism.

Namespace

Drupal\search_api_saved_searches\Plugin\search_api_saved_searches\notification

Code

protected function getAvailableTokensList(array $types) {

  // Code taken from \Drupal\views\Plugin\views\PluginBase::globalTokenForm().
  $token_items = [];
  $infos = $this
    ->getTokenService()
    ->getInfo();
  foreach ($infos['tokens'] as $type => $tokens) {
    if (!in_array($type, $types)) {
      continue;
    }
    $item = [
      '#markup' => Html::escape($type),
      'children' => [],
    ];
    foreach ($tokens as $name => $info) {
      $item['children'][$name] = "[{$type}:{$name}] - {$info['name']}: {$info['description']}";
    }
    $token_items[$type] = $item;
  }
  $available_tokens = [
    '#type' => 'details',
    '#title' => $this
      ->t('Available token replacements'),
  ];
  $available_tokens['list'] = [
    '#theme' => 'item_list',
    '#items' => $token_items,
  ];
  return $available_tokens;
}