You are here

public function PluginBase::getAvailableGlobalTokens in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/src/Plugin/views/PluginBase.php \Drupal\views\Plugin\views\PluginBase::getAvailableGlobalTokens()
  2. 9 core/modules/views/src/Plugin/views/PluginBase.php \Drupal\views\Plugin\views\PluginBase::getAvailableGlobalTokens()

File

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

Class

PluginBase

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;
}