You are here

public function PluginBase::getAvailableGlobalTokens in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 422
Contains \Drupal\views\Plugin\views\PluginBase.

Class

PluginBase
Base class for any views plugin types.

Namespace

Drupal\views\Plugin\views

Code

public function getAvailableGlobalTokens($prepared = FALSE, array $types = array()) {
  $info = \Drupal::token()
    ->getInfo();

  // Site and view tokens should always be available.
  $types += array(
    'site',
    'view',
  );
  $available = array_intersect_key($info['tokens'], array_flip($types));

  // Construct the token string for each token.
  if ($prepared) {
    $prepared = array();
    foreach ($available as $type => $tokens) {
      foreach (array_keys($tokens) as $token) {
        $prepared[$type][] = "[{$type}:{$token}]";
      }
    }
    return $prepared;
  }
  return $available;
}