function Token::getInfo

Same name in this branch
  1. 9 core/lib/Drupal/Core/Render/Element/Token.php \Drupal\Core\Render\Element\Token::getInfo()
Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Render/Element/Token.php \Drupal\Core\Render\Element\Token::getInfo()
  2. 8.9.x core/lib/Drupal/Core/Utility/Token.php \Drupal\Core\Utility\Token::getInfo()
  3. 10 core/lib/Drupal/Core/Render/Element/Token.php \Drupal\Core\Render\Element\Token::getInfo()
  4. 10 core/lib/Drupal/Core/Utility/Token.php \Drupal\Core\Utility\Token::getInfo()
  5. 11.x core/lib/Drupal/Core/Render/Element/Token.php \Drupal\Core\Render\Element\Token::getInfo()
  6. 11.x core/lib/Drupal/Core/Utility/Token.php \Drupal\Core\Utility\Token::getInfo()

Returns metadata describing supported tokens.

The metadata array contains token type, name, and description data as well as an optional pointer indicating that the token chains to another set of tokens.

Return value

array An associative array of token information, grouped by token type. The array structure is identical to that of hook_token_info().

See also

hook_token_info()

File

core/lib/Drupal/Core/Utility/Token.php, line 424

Class

Token
Drupal placeholder/token replacement system.

Namespace

Drupal\Core\Utility

Code

public function getInfo() {
    if (is_null($this->tokenInfo)) {
        $cache_id = 'token_info:' . $this->languageManager
            ->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)
            ->getId();
        $cache = $this->cache
            ->get($cache_id);
        if ($cache) {
            $this->tokenInfo = $cache->data;
        }
        else {
            $this->tokenInfo = $this->moduleHandler
                ->invokeAll('token_info');
            $this->moduleHandler
                ->alter('token_info', $this->tokenInfo);
            $this->cache
                ->set($cache_id, $this->tokenInfo, CacheBackendInterface::CACHE_PERMANENT, [
                static::TOKEN_INFO_CACHE_TAG,
            ]);
        }
    }
    return $this->tokenInfo;
}

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