diff --git a/core/lib/Drupal/Core/Template/TwigEnvironment.php b/core/lib/Drupal/Core/Template/TwigEnvironment.php index d8da1ca..d8ff7e7 100644 --- a/core/lib/Drupal/Core/Template/TwigEnvironment.php +++ b/core/lib/Drupal/Core/Template/TwigEnvironment.php @@ -10,6 +10,7 @@ use Drupal\Core\PhpStorage\PhpStorageFactory; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Extension\ThemeHandlerInterface; +use ReflectionObject; /** * A class that defines a Twig environment for Drupal. @@ -74,11 +75,11 @@ public function __construct(\Twig_LoaderInterface $loader = NULL, $options = arr /** * Checks if the compiled template needs an update. */ - protected function isFresh($cache_filename, $name) { + protected function isFresh($cache_filename, $name, $inline = FALSE) { $cid = 'twig:' . $cache_filename; $obj = $this->cache_object->get($cid); $mtime = isset($obj->data) ? $obj->data : FALSE; - return $mtime === FALSE || $this->isTemplateFresh($name, $mtime); + return $mtime === FALSE || $this->isTemplateFresh($name, $mtime, $inline); } /** @@ -153,7 +154,7 @@ public function loadTemplate($name, $index = NULL, $inline = 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)) { + if ($this->isAutoReload() && !$this->isFresh($cache_filename, $name, $inline)) { $this->updateCompiledTemplate($cache_filename, $name, $inline); } @@ -171,6 +172,17 @@ public function loadTemplate($name, $index = NULL, $inline = FALSE) { return $this->loadedTemplates[$cls] = new $cls($this); } + public function isTemplateFresh($name, $time, $inline = FALSE) { + foreach ($this->extensions as $extension) { + $r = new ReflectionObject($extension); + if (filemtime($r->getFileName()) > $time) { + return FALSE; + } + } + + return $this->getLoader($inline)->isFresh($name, $time, $inline); + } + /** * Gets the PHP code storage object to use for the compiled Twig files. *