diff --git a/core/lib/Drupal/Core/Template/TwigEnvironment.php b/core/lib/Drupal/Core/Template/TwigEnvironment.php index 2c00a1f..762271f 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 LogicException; /** * A class that defines a Twig environment for Drupal. @@ -45,6 +46,10 @@ public function __construct(\Twig_LoaderInterface $loader = NULL, $options = arr // @todo Pass as arguments from the DIC. $this->cache_object = \Drupal::cache(); + // Ensure that twig.engine is loaded, given that it is needed to render a + // template because functions like twig_drupal_escape_filter are called. + require_once 'core/themes/engines/twig/twig.engine'; + // Set twig path namespace for themes and modules. $namespaces = array(); foreach ($module_handler->getModuleList() as $name => $extension) { @@ -79,6 +84,9 @@ public function needsUpdate($cache_filename, $name) { /** * Compile the source and write the compiled template to disk. + * + * @param bool $inline + * TRUE, if the $cache_filename is a rendered template. */ public function updateCompiledTemplate($cache_filename, $name, $inline = FALSE) { $source = $this->getLoader($inline)->getSource($name); @@ -89,6 +97,14 @@ public function updateCompiledTemplate($cache_filename, $name, $inline = FALSE) $this->cache_object->set($cid, REQUEST_TIME); } + /** + * Gets the Loader instance. + * + * @param bool $inline + * TRUE, if the string loader is requested. + * + * @return \Twig_LoaderInterface A Twig_LoaderInterface instance + */ public function getLoader($inline = FALSE) { if (NULL === $this->loader) { throw new LogicException('You must set a loader first.'); @@ -103,6 +119,21 @@ public function getLoader($inline = FALSE) { * * This is a straight copy from loadTemplate() changed to use * drupal_php_storage(). + * + * @param string $name + * The template name or the string which should be rendered as template. + * @param int $index + * The index if it is an embedded template. + * @param bool $inline + * TRUE, if the $name is a rendered template. + * + * @return \Twig_TemplateInterface + * A template instance representing the given template name. + * + * @throws \Twig_Error_Loader + * When the template cannot be found. + * @throws \Twig_Error_Syntax + * When an error occurred during compilation. */ public function loadTemplate($name, $index = NULL, $inline = FALSE) { $cls = $this->getTemplateClass($name, $index, $inline); @@ -153,7 +184,17 @@ protected function storage() { } /** - * {@inheritdoc} + * Gets the template class associated with the given string. + * + * @param string $name + * The name for which to calculate the template class name. + * @param int $index + * The index if it is an embedded template. + * @param bool $inline + * TRUE, if the $name is a rendered template. + * + * @return string + * The template class name. */ public function getTemplateClass($name, $index = NULL, $inline = FALSE) { // We override this method to add caching because it gets called multiple diff --git a/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php b/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php index f719bc6..7c100ed 100644 --- a/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php +++ b/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php @@ -10,9 +10,9 @@ use Drupal\simpletest\KernelTestBase; /** - * Tests the twig enviroment. + * Tests the twig environment. * - * @see \Drupal\Core\Template\TwigEnviroment + * @see \Drupal\Core\Template\TwigEnvironment * @group Twig */ class TwigEnvironmentTest extends KernelTestBase {