diff --git a/token.module b/token.module index 0617f92..3e93fa2 100644 --- a/token.module +++ b/token.module @@ -304,9 +304,7 @@ function token_field_delete_instance($instance) { * Clear token caches and static variables. */ function token_clear_cache() { - if (db_table_exists('cache_token')) { - \Drupal::cache('cache_token')->flush(); - } + \Drupal::token()->resetInfo(); drupal_static_reset('token_get_info'); drupal_static_reset('token_get_global_token_types'); drupal_static_reset('token_get_entity_mapping'); @@ -435,40 +433,30 @@ function token_get_info($token_type = NULL, $token = NULL) { $token_info = &$drupal_static_fast['token_info']; if (empty($token_info)) { - $langcode = \Drupal::languageManager()->getCurrentLanguage()->id; - $cid = "info:{$langcode}"; - - if ($cache = \Drupal::cache('cache_token')->get($cid)) { - $token_info = $cache->data; - } - else { - $token_info = \Drupal::token()->getInfo(); - - foreach (array_keys($token_info['types']) as $type_key) { - if (isset($token_info['types'][$type_key]['type'])) { - $base_type = $token_info['types'][$type_key]['type']; - // If this token type extends another token type, then merge in - // the base token type's tokens. - if (isset($token_info['tokens'][$base_type])) { - $token_info['tokens'] += array($type_key => array()); - $token_info['tokens'][$type_key] += $token_info['tokens'][$base_type]; - } - } - else { - // Add a 'type' value to each token type so we can properly use - // token_type_load(). - $token_info['types'][$type_key]['type'] = $type_key; + $token_info = \Drupal::token()->getInfo(); + + // @todo: Move this into the token service and deprecate this function. + foreach (array_keys($token_info['types']) as $type_key) { + if (isset($token_info['types'][$type_key]['type'])) { + $base_type = $token_info['types'][$type_key]['type']; + // If this token type extends another token type, then merge in + // the base token type's tokens. + if (isset($token_info['tokens'][$base_type])) { + $token_info['tokens'] += array($type_key => array()); + $token_info['tokens'][$type_key] += $token_info['tokens'][$base_type]; } } - - // Pre-sort tokens. - uasort($token_info['types'], 'token_asort_tokens'); - foreach (array_keys($token_info['tokens']) as $type) { - uasort($token_info['tokens'][$type], 'token_asort_tokens'); + else { + // Add a 'type' value to each token type so we can properly use + // token_type_load(). + $token_info['types'][$type_key]['type'] = $type_key; } + } - // Store info in cache for future use. - \Drupal::cache('cache_token')->set($cid, $token_info); + // Pre-sort tokens. + uasort($token_info['types'], 'token_asort_tokens'); + foreach (array_keys($token_info['tokens']) as $type) { + uasort($token_info['tokens'][$type], 'token_asort_tokens'); } } @@ -829,18 +817,18 @@ function token_build_tree($token_type, array $options = array()) { } $langcode = \Drupal::languageManager()->getCurrentLanguage()->id; - $tree_cid = "tree:{$token_type}:{$langcode}:{$options['depth']}"; + $tree_cid = "token_tree:{$token_type}:{$langcode}:{$options['depth']}"; - // If we do not have this base tree in the static cache, check {cache_token} + // If we do not have this base tree in the static cache, check the cache // otherwise generate and store it in the cache. if (!isset($trees[$tree_cid])) { - if ($cache = \Drupal::cache('cache_token')->get($tree_cid)) { + if ($cache = \Drupal::cache('data')->get($tree_cid)) { $trees[$tree_cid] = $cache->data; } else { $options['parents'] = array(); $trees[$tree_cid] = _token_build_tree($token_type, $options); - \Drupal::cache('cache_token')->set($tree_cid, $trees[$tree_cid]); + \Drupal::cache('data')->set($tree_cid, $trees[$tree_cid]); } } @@ -1080,7 +1068,7 @@ function token_render_cache_get($elements) { if (!$cid = drupal_render_cid_create($elements)) { return FALSE; } - $bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'cache'; + $bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'render'; if (!empty($cid) && $cache = \Drupal::cache($bin)->get($cid)) { // Add additional libraries, JavaScript, CSS and other data attached diff --git a/token.pages.inc b/token.pages.inc index dbc64a2..c48c5aa 100644 --- a/token.pages.inc +++ b/token.pages.inc @@ -108,7 +108,6 @@ function theme_token_tree($variables) { $element = array( '#cache' => array( 'cid' => 'tree-rendered:' . hash('sha256', serialize(array('token_types' => $token_types, 'global_types' => NULL) + $variables)), - 'bin' => 'cache_token', ), ); if ($cached_output = token_render_cache_get($element)) { diff --git a/token.services.yml b/token.services.yml index 71fe59b..0baad47 100644 --- a/token.services.yml +++ b/token.services.yml @@ -1,8 +1 @@ services: - cache.cache_token: - class: Drupal\Core\Cache\CacheBackendInterface - tags: - - { name: cache.bin } - factory_method: get - factory_service: cache_factory - arguments: [cache_token]