diff --git a/core/lib/Drupal/Core/Template/TwigPhpStorageCache.php b/core/lib/Drupal/Core/Template/TwigPhpStorageCache.php index 258aa36..f83605e 100644 --- a/core/lib/Drupal/Core/Template/TwigPhpStorageCache.php +++ b/core/lib/Drupal/Core/Template/TwigPhpStorageCache.php @@ -74,8 +74,18 @@ protected function storage() { public function generateKey($name, $className) { $hash = hash('sha256', $className); + if (strpos($name, '{# inline_template_start #}') === 0) { + // $name is an inline template, and can have characters that are not valid + // for a filename. $hash is unique for each inline template so we just use + // the generic name 'inline-template' here. + $name = 'inline-template'; + } + else { + $name = basename($name); + } + // The first part is what is invalidated. - return $this->templateCacheFilenamePrefix . '_' . basename($name) . '_' . $hash; + return $this->templateCacheFilenamePrefix . '_' . $name . '_' . $hash; } /** diff --git a/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php b/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php index 1bab9bf..6423c23 100644 --- a/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php +++ b/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php @@ -65,6 +65,15 @@ public function testInlineTemplate() { // Render it twice so that twig caching is triggered. $this->assertEqual($renderer->renderRoot($element), 'test-with-context muuh'); $this->assertEqual($renderer->renderRoot($element_copy), 'test-with-context muuh'); + + // Tests caching of inline templates. + $name = '{# inline_template_start #}test-with-context {{ llama }}'; + $hash = $this->container->getParameter('twig_extension_hash'); + + $cache = $environment->getCache(); + $class = $environment->getTemplateClass($name); + $expected = $hash . '_inline-template' . '_' . hash('sha256', $class); + $this->assertEqual($expected, $cache->generateKey($name, $class)); } /**