core/lib/Drupal/Core/Template/TwigExtension.php | 2 -- core/modules/system/src/Tests/Theme/EngineTwigTest.php | 8 ++++++++ .../modules/twig_theme_test/src/TwigThemeTestController.php | 9 +++++++++ .../templates/twig_theme_test.attach_library.html.twig | 1 + .../system/tests/modules/twig_theme_test/twig_theme_test.module | 4 ++++ .../tests/modules/twig_theme_test/twig_theme_test.routing.yml | 7 +++++++ 6 files changed, 29 insertions(+), 2 deletions(-) diff --git a/core/lib/Drupal/Core/Template/TwigExtension.php b/core/lib/Drupal/Core/Template/TwigExtension.php index 625aa0e..a2b1f59 100644 --- a/core/lib/Drupal/Core/Template/TwigExtension.php +++ b/core/lib/Drupal/Core/Template/TwigExtension.php @@ -286,8 +286,6 @@ public function isUrlGenerationSafe(\Twig_Node $args_node) { * {{ attach_library('extension/library_name') }} * @endcode * - * This makes for a much better TX. - * * @param string $library * An asset library. */ diff --git a/core/modules/system/src/Tests/Theme/EngineTwigTest.php b/core/modules/system/src/Tests/Theme/EngineTwigTest.php index 750ae2e..ff84af7 100644 --- a/core/modules/system/src/Tests/Theme/EngineTwigTest.php +++ b/core/modules/system/src/Tests/Theme/EngineTwigTest.php @@ -111,4 +111,12 @@ public function testTwigFileUrls() { $this->assertRaw('
file_url: ' . $filepath . '
'); } + /** + * Tests the attach of asset libraries. + */ + public function testTwigAttachLibrary() { + $this->drupalGet('/twig-theme-test/attach-library'); + $this->assertRaw('ckeditor.js'); + } + } diff --git a/core/modules/system/tests/modules/twig_theme_test/src/TwigThemeTestController.php b/core/modules/system/tests/modules/twig_theme_test/src/TwigThemeTestController.php index ff49bd6..50d6c99 100644 --- a/core/modules/system/tests/modules/twig_theme_test/src/TwigThemeTestController.php +++ b/core/modules/system/tests/modules/twig_theme_test/src/TwigThemeTestController.php @@ -69,6 +69,15 @@ public function fileUrlRender() { } /** + * Renders for testing attach_library functions in a Twig template. + */ + public function attachLibraryRender() { + return array( + '#theme' => 'twig_theme_test_attach_library', + ); + } + + /** * Menu callback for testing the Twig registry loader. */ public function registryLoaderRender() { diff --git a/core/modules/system/tests/modules/twig_theme_test/templates/twig_theme_test.attach_library.html.twig b/core/modules/system/tests/modules/twig_theme_test/templates/twig_theme_test.attach_library.html.twig new file mode 100644 index 0000000..0784ab9 --- /dev/null +++ b/core/modules/system/tests/modules/twig_theme_test/templates/twig_theme_test.attach_library.html.twig @@ -0,0 +1 @@ +{{ attach_library('core/ckeditor') }} diff --git a/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.module b/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.module index 7f6fe35..021d039 100644 --- a/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.module +++ b/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.module @@ -50,6 +50,10 @@ function twig_theme_test_theme($existing, $type, $theme, $path) { 'variables' => array(), 'template' => 'twig_theme_test.file_url', ); + $items['twig_theme_test_attach_library'] = array( + 'variables' => array(), + 'template' => 'twig_theme_test.attach_library', + ); return $items; } diff --git a/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.routing.yml b/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.routing.yml index 1001b47..c372c22 100644 --- a/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.routing.yml +++ b/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.routing.yml @@ -40,6 +40,13 @@ twig_theme_test_file_url: requirements: _access: 'TRUE' +twig_theme_test_attach_library: + path: '/twig-theme-test/attach-library' + defaults: + _controller: '\Drupal\twig_theme_test\TwigThemeTestController::attachLibraryRender' + requirements: + _access: 'TRUE' + twig_theme_test_registry_loader: path: '/twig-theme-test/registry-loader' defaults: