core/lib/Drupal/Core/Template/TwigEnvironment.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/lib/Drupal/Core/Template/TwigEnvironment.php b/core/lib/Drupal/Core/Template/TwigEnvironment.php index 32e780b..a060f48 100644 --- a/core/lib/Drupal/Core/Template/TwigEnvironment.php +++ b/core/lib/Drupal/Core/Template/TwigEnvironment.php @@ -17,6 +17,11 @@ class TwigEnvironment extends \Twig_Environment { /** + * Key name of the Twig cache prefix metadata key-value pair in State. + */ + const CACHE_PREFIX_METADATA_KEY = 'twig_extension_hash_prefix'; + + /** * The state service. * * @var \Drupal\Core\State\StateInterface @@ -72,7 +77,7 @@ public function __construct($root, CacheBackendInterface $cache, $twig_extension $this->addExtension($sandbox); if ($options['cache'] === TRUE) { - $current = $state->get('twig_extension_hash_prefix', ['twig_extension_hash' => '']); + $current = $state->get(static::CACHE_PREFIX_METADATA_KEY, ['twig_extension_hash' => '']); if ($current['twig_extension_hash'] !== $twig_extension_hash || empty($current['twig_cache_prefix'])) { $current = [ 'twig_extension_hash' => $twig_extension_hash, @@ -80,7 +85,7 @@ public function __construct($root, CacheBackendInterface $cache, $twig_extension 'twig_cache_prefix' => uniqid(), ]; - $state->set('twig_extension_hash_prefix', $current); + $state->set(static::CACHE_PREFIX_METADATA_KEY, $current); } $this->twigCachePrefix = $current['twig_cache_prefix']; @@ -97,7 +102,7 @@ public function __construct($root, CacheBackendInterface $cache, $twig_extension * @see \drupal_flush_all_caches */ public function invalidate() { - $this->state->delete('twig_extension_hash_prefix'); + $this->state->delete(static::CACHE_PREFIX_METADATA_KEY); } /**