diff -u b/core/core.services.yml b/core/core.services.yml --- b/core/core.services.yml +++ b/core/core.services.yml @@ -66,6 +66,13 @@ factory_method: get factory_service: cache_factory arguments: [path] + cache.token: + class: Drupal\Core\Cache\CacheBackendInterface + tags: + - { name: cache.bin } + factory_method: get + factory_service: cache_factory + arguments: [token] config.cachedstorage.storage: class: Drupal\Core\Config\FileStorage factory_class: Drupal\Core\Config\FileStorageFactory @@ -596,7 +603,7 @@ arguments: ['@module_handler'] token: class: Drupal\Core\Utility\Token - arguments: ['@module_handler'] + arguments: ['@module_handler', '@cache.token', '@language_manager'] batch.storage: class: Drupal\Core\Batch\BatchStorage arguments: ['@database'] @@ -604,7 +611,7 @@ arguments: ['@module_handler'] token: class: Drupal\Core\Utility\Token - arguments: ['@module_handler', '@cache.cache', '@language_manager'] + arguments: ['@module_handler'] batch.storage: class: Drupal\Core\Batch\BatchStorage arguments: ['@database'] diff -u b/core/lib/Drupal/Core/Utility/Token.php b/core/lib/Drupal/Core/Utility/Token.php --- b/core/lib/Drupal/Core/Utility/Token.php +++ b/core/lib/Drupal/Core/Utility/Token.php @@ -9,7 +9,8 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\Language\LanguageManager; +use Drupal\Core\Language\Language; +use Drupal\Core\Language\LanguageManagerInterface; /** * Drupal placeholder/token replacement system. @@ -57,28 +58,23 @@ class Token { /** - * The cache. + * The token cache. * * @var \Drupal\Core\Cache\CacheBackendInterface */ protected $cache; /** - * The tag to cache token info with. - */ - const CACHE_TAG = 'token_info'; - - /** * The language manager. * - * @var \Drupal\Core\Language\LanguageManager + * @var \Drupal\Core\Language\LanguageManagerInterface */ protected $languageManager; /** * Token definitions. * - * @var array|null + * @var array[]|null * An array of token definitions, or NULL when the definitions are not set. * * @see self::setInfo() @@ -95,12 +91,16 @@ protected $moduleHandler; /** - * Constructor. + * Constructs a new class instance. * * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler. * @param \Drupal\Core\Cache\CacheBackendInterface $cache + * The token cache. + * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager + * The language manager. */ - public function __construct(ModuleHandlerInterface $module_handler, CacheBackendInterface $cache, LanguageManager $language_manager) { + public function __construct(ModuleHandlerInterface $module_handler, CacheBackendInterface $cache, LanguageManagerInterface $language_manager) { $this->cache = $cache; $this->languageManager = $language_manager; $this->moduleHandler = $module_handler; @@ -304,7 +304,7 @@ */ public function getInfo() { if (is_null($this->tokenInfo)) { - $cache_id = 'token_info:' . $this->languageManager->getLanguage()->id; + $cache_id = 'token_info:' . $this->languageManager->getCurrentLanguage(Language::TYPE_CONTENT)->id; $cache = $this->cache->get($cache_id); if ($cache) { $this->tokenInfo = $cache->data; @@ -312,7 +312,7 @@ 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, array(static::CACHE_TAG)); + $this->cache->set($cache_id, $this->tokenInfo); } } @@ -338,5 +338,5 @@ public function resetInfo() { $this->tokenInfo = NULL; - $this->cache->deleteTags(array(static::CACHE_TAG)); + $this->cache->deleteAll(); } } diff -u b/core/tests/Drupal/Tests/Core/Utility/TokenUnitTest.php b/core/tests/Drupal/Tests/Core/Utility/TokenUnitTest.php --- b/core/tests/Drupal/Tests/Core/Utility/TokenUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Utility/TokenUnitTest.php @@ -1,16 +1,18 @@ id = $this->randomName(); $this->languageManager->expects($this->once()) - ->method('getLanguage') + ->method('getCurrentLanguage') + ->with(Language::TYPE_CONTENT) ->will($this->returnValue($language)); - // The persistent cache should only be hit once, after which the info is + // The persistent cache must only be hit once, after which the info is // cached statically. $this->cache->expects($this->once()) ->method('get'); @@ -103,12 +106,12 @@ ->method('alter') ->with('token_info', $token_info); - // Get the information for the first time. The cache should be got, the - // hooks invoked, and the cache should be set. + // Get the information for the first time. The cache should be checked, the + // hooks invoked, and the info should be set to the cache should. $this->token->getInfo(); - // Get the information for the second time. The data should be returned from - // the static cache, so the cache should not be accessed and the hooks - // should not be invoked. + // Get the information for the second time. The data must be returned from + // the static cache, so the persistent cache must not be accessed and the + // hooks must not be invoked. $this->token->getInfo(); }