diff --git a/core/lib/Drupal/Core/Template/TwigEnvironment.php b/core/lib/Drupal/Core/Template/TwigEnvironment.php index 346dcc2..93ad1aa 100644 --- a/core/lib/Drupal/Core/Template/TwigEnvironment.php +++ b/core/lib/Drupal/Core/Template/TwigEnvironment.php @@ -117,12 +117,7 @@ public function loadTemplate($name, $index = NULL) { if (!class_exists($cls, FALSE)) { $cache_filename = $this->getCacheFilename($name); - if ($cache_filename === FALSE) { - $compiled_source = $this->compileSource($this->loader->getSource($name), $name); - eval('?' . '>' . $compiled_source); - } - else { - + if ($cache_filename !== FALSE) { // If autoreload is on, check that the template has not been // modified since the last compilation. if ($this->isAutoReload() && !$this->isFresh($cache_filename, $name)) { @@ -134,6 +129,10 @@ public function loadTemplate($name, $index = NULL) { $this->storage()->load($cache_filename); } } + if (!class_exists($cls, FALSE)) { + $compiled_source = $this->compileSource($this->loader->getSource($name), $name); + eval('?' . '>' . $compiled_source); + } } if (!$this->runtimeInitialized) { diff --git a/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php b/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php index 235db35..fbc1399 100644 --- a/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php +++ b/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php @@ -8,6 +8,7 @@ namespace Drupal\system\Tests\Theme; use Drupal\Component\Utility\SafeMarkup; +use Drupal\Core\PhpStorage\PhpStorageFactory; use Drupal\Core\Site\Settings; use Drupal\simpletest\KernelTestBase; @@ -46,6 +47,19 @@ public function testInlineTemplate() { ); $this->assertEqual($renderer->renderRoot($element), 'test-with-context '); + // Simulate an invalid, existing file in the storage. + $name = 'maintenance-page.html.twig'; + $cache_file = $environment->getCacheFilename($name); + $storage = PhpStorageFactory::get('twig'); + $storage->save($cache_file, ' 'inline_template', + '#template' => $name, + ); + $this->assertEqual($renderer->renderRoot($element), $name); + // Enable twig_auto_reload and twig_debug. $settings = Settings::getAll(); $settings['twig_debug'] = TRUE;