diff --git a/core/lib/Drupal/Core/Template/TwigEnvironment.php b/core/lib/Drupal/Core/Template/TwigEnvironment.php index 886f555..24c9084 100644 --- a/core/lib/Drupal/Core/Template/TwigEnvironment.php +++ b/core/lib/Drupal/Core/Template/TwigEnvironment.php @@ -38,7 +38,7 @@ public function __construct(\Twig_LoaderInterface $loader = NULL, $options = arr // @todo Pass as arguments from the DIC. $this->cache_object = cache(); - // Set twig path namespace for themes and modules + // Set twig path namespace for themes and modules. $namespaces = $module_handler->getModuleList(); foreach ($theme_handler->listInfo() as $theme => $info) { $namespaces[$theme] = $info->filename; diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/TwigNamespaceTest.php b/core/modules/system/lib/Drupal/system/Tests/Theme/TwigNamespaceTest.php index 1068a3f..2d5ea69 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Theme/TwigNamespaceTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Theme/TwigNamespaceTest.php @@ -41,23 +41,30 @@ function setUp() { } /** - * Check to see if a value is a twig template. + * Checks to see if a value is a twig template. */ public function assertTwigTemplate($value, $message = '', $group = 'Other') { $this->assertTrue($value instanceof \Twig_Template, $message, $group); } + /** + * Tests template discovery using namespaces. + */ public function testTemplateDiscovery() { - // Enabled module - $this->assertTwigTemplate($this->twig->resolveTemplate('@node/node.html.twig'), 'Found node.tpl.php in node module.'); + // Tests resolving namespaced templates in modules. + $this->assertTwigTemplate($this->twig->resolveTemplate('@node/node.html.twig'), 'Found node.html.twig in node module.'); - // Enabled theme - $this->assertTwigTemplate($this->twig->resolveTemplate('@bartik/page.html.twig'), 'Found page.html.twig in bartik theme.'); + // Tests resolving namespaced templates in themes. + $this->assertTwigTemplate($this->twig->resolveTemplate('@bartik/page.html.twig'), 'Found page.html.twig in Bartik theme.'); } + /** + * Tests template extension and includes using namespaces. + */ public function testTwigNamespaces() { // Test twig @extends and @include in template files. - $this->drupalSetContent(theme('twig_namespace_test')); + $test = array('#theme' => 'twig_namespace_test'); + $this->drupalSetContent(drupal_render($test)); $this->assertText('This line is from twig_namespace_a/templates/test.html.twig'); $this->assertText('This line is from twig_namespace_b/templates/test.html.twig'); diff --git a/core/modules/system/tests/modules/twig_theme_test/modules/twig_namespace_a/templates/test.html.twig b/core/modules/system/tests/modules/twig_theme_test/modules/twig_namespace_a/templates/test.html.twig index ed52e5e..94e1fc9 100644 --- a/core/modules/system/tests/modules/twig_theme_test/modules/twig_namespace_a/templates/test.html.twig +++ b/core/modules/system/tests/modules/twig_theme_test/modules/twig_namespace_a/templates/test.html.twig @@ -1,5 +1,5 @@ This line is from twig_namespace_a/templates/test.html.twig -{% block content %} +{% block content %} This text is in a block. {% endblock %} diff --git a/core/modules/system/tests/modules/twig_theme_test/templates/twig_namespace_test.html.twig b/core/modules/system/tests/modules/twig_theme_test/templates/twig_namespace_test.html.twig index ea9a806..5ac6e38 100644 --- a/core/modules/system/tests/modules/twig_theme_test/templates/twig_namespace_test.html.twig +++ b/core/modules/system/tests/modules/twig_theme_test/templates/twig_namespace_test.html.twig @@ -1,5 +1,5 @@ {% extends "@twig_namespace_a/test.html.twig" %} -{% block content %} +{% block content %} {% include "@twig_namespace_b/test.html.twig" %} {% endblock %}