function PluginBase::getAvailableGlobalTokens

Same name and namespace in other branches
  1. 11.x core/modules/views/src/Plugin/views/PluginBase.php \Drupal\views\Plugin\views\PluginBase::getAvailableGlobalTokens()
  2. 10 core/modules/views/src/Plugin/views/PluginBase.php \Drupal\views\Plugin\views\PluginBase::getAvailableGlobalTokens()
  3. 8.9.x core/modules/views/src/Plugin/views/PluginBase.php \Drupal\views\Plugin\views\PluginBase::getAvailableGlobalTokens()

File

core/modules/views/src/Plugin/views/PluginBase.php, line 432

Class

PluginBase
Base class for any views plugin types.

Namespace

Drupal\views\Plugin\views

Code

public function getAvailableGlobalTokens($prepared = FALSE, array $types = []) {
  $info = \Drupal::token()->getInfo();
  // Site and view tokens should always be available.
  $types += [
    'site',
    'view',
  ];
  $available = array_intersect_key($info['tokens'], array_flip($types));
  // Construct the token string for each token.
  if ($prepared) {
    $prepared = [];
    foreach ($available as $type => $tokens) {
      foreach (array_keys($tokens) as $token) {
        $prepared[$type][] = "[{$type}:{$token}]";
      }
    }
    return $prepared;
  }
  return $available;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.