public function PluginBase::getAvailableGlobalTokens in Drupal 8
Same name and namespace in other branches
- 9 core/modules/views/src/Plugin/views/PluginBase.php \Drupal\views\Plugin\views\PluginBase::getAvailableGlobalTokens()
- 10 core/modules/views/src/Plugin/views/PluginBase.php \Drupal\views\Plugin\views\PluginBase::getAvailableGlobalTokens()
Returns an array of available token replacements.
Parameters
bool $prepared: Whether to return the raw token info for each token or an array of prepared tokens for each type. E.g. "[view:name]".
array $types: An array of additional token types to return, defaults to 'site' and 'view'.
Return value
array An array of available token replacement info or tokens, grouped by type.
Overrides ViewsPluginInterface::getAvailableGlobalTokens
1 call to PluginBase::getAvailableGlobalTokens()
- PluginBase::globalTokenForm in core/modules/ views/ src/ Plugin/ views/ PluginBase.php 
- Adds elements for available core tokens to a form.
File
- core/modules/ views/ src/ Plugin/ views/ PluginBase.php, line 429 
Class
- PluginBase
- Base class for any views plugin types.
Namespace
Drupal\views\Plugin\viewsCode
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;
}