Mercurial > hg > isophonics-drupal-site
diff core/lib/Drupal/Core/Template/TwigEnvironment.php @ 18:af1871eacc83
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:33:08 +0100 |
parents | 129ea1e6d783 |
children |
line wrap: on
line diff
--- a/core/lib/Drupal/Core/Template/TwigEnvironment.php Thu Feb 28 13:21:36 2019 +0000 +++ b/core/lib/Drupal/Core/Template/TwigEnvironment.php Thu May 09 15:33:08 2019 +0100 @@ -36,6 +36,11 @@ */ protected $templateClasses; + /** + * The template cache filename prefix. + * + * @var string + */ protected $twigCachePrefix = ''; /** @@ -55,11 +60,12 @@ * @param array $options * The options for the Twig environment. */ - public function __construct($root, CacheBackendInterface $cache, $twig_extension_hash, StateInterface $state, \Twig_LoaderInterface $loader = NULL, $options = []) { + public function __construct($root, CacheBackendInterface $cache, $twig_extension_hash, StateInterface $state, \Twig_LoaderInterface $loader = NULL, array $options = []) { $this->state = $state; // Ensure that twig.engine is loaded, given that it is needed to render a // template because functions like TwigExtension::escapeFilter() are called. + // @todo remove in Drupal 9.0.0 https://www.drupal.org/node/3011393. require_once $root . '/core/themes/engines/twig/twig.engine'; $this->templateClasses = []; @@ -72,11 +78,6 @@ ]; // Ensure autoescaping is always on. $options['autoescape'] = 'html'; - - $policy = new TwigSandboxPolicy(); - $sandbox = new \Twig_Extension_Sandbox($policy, TRUE); - $this->addExtension($sandbox); - if ($options['cache'] === TRUE) { $current = $state->get(static::CACHE_PREFIX_METADATA_KEY, ['twig_extension_hash' => '']); if ($current['twig_extension_hash'] !== $twig_extension_hash || empty($current['twig_cache_prefix'])) { @@ -93,8 +94,11 @@ $options['cache'] = new TwigPhpStorageCache($cache, $this->twigCachePrefix); } - $this->loader = $loader; - parent::__construct($this->loader, $options); + $this->setLoader($loader); + parent::__construct($this->getLoader(), $options); + $policy = new TwigSandboxPolicy(); + $sandbox = new \Twig_Extension_Sandbox($policy, TRUE); + $this->addExtension($sandbox); } /** @@ -105,7 +109,6 @@ public function invalidate() { PhpStorageFactory::get('twig')->deleteAll(); $this->templateClasses = []; - $this->loadedTemplates = []; $this->state->delete(static::CACHE_PREFIX_METADATA_KEY); } @@ -137,7 +140,7 @@ // node.html.twig for the output of each node and the same compiled class. $cache_index = $name . (NULL === $index ? '' : '_' . $index); if (!isset($this->templateClasses[$cache_index])) { - $this->templateClasses[$cache_index] = $this->templateClassPrefix . hash('sha256', $this->loader->getCacheKey($name)) . (NULL === $index ? '' : '_' . $index); + $this->templateClasses[$cache_index] = parent::getTemplateClass($name, $index); } return $this->templateClasses[$cache_index]; } @@ -167,7 +170,7 @@ public function renderInline($template_string, array $context = []) { // Prefix all inline templates with a special comment. $template_string = '{# inline_template_start #}' . $template_string; - return Markup::create($this->loadTemplate($template_string, NULL)->render($context)); + return Markup::create($this->createTemplate($template_string)->render($context)); } }