diff --git a/core/lib/Drupal/Core/Template/TwigExtension.php b/core/lib/Drupal/Core/Template/TwigExtension.php index 05c7390..cf3500e 100644 --- a/core/lib/Drupal/Core/Template/TwigExtension.php +++ b/core/lib/Drupal/Core/Template/TwigExtension.php @@ -82,6 +82,10 @@ public function getFilters() { // Array filters. new \Twig_SimpleFilter('without', 'twig_without'), + + // CSS class and ID filters. + new \Twig_SimpleFilter('clean_class', 'drupal_html_class'), + new \Twig_SimpleFilter('clean_id', 'drupal_clean_id_identifier'), ); } diff --git a/core/modules/system/src/Tests/Theme/TwigFilterTest.php b/core/modules/system/src/Tests/Theme/TwigFilterTest.php index c22be7f..5a285c7 100644 --- a/core/modules/system/src/Tests/Theme/TwigFilterTest.php +++ b/core/modules/system/src/Tests/Theme/TwigFilterTest.php @@ -111,6 +111,10 @@ public function testTwigWithoutFilter() { 'expected' => '
All attributes again.
', 'message' => 'All attributes printed again.', ), + array( + 'expected' => '
ID and class. Having the same ID twice is not valid markup but we want to make sure the filter doesn\'t use drupal_html_id().
', + 'message' => 'Class and ID filtered.', + ), ); foreach ($elements as $element) { diff --git a/core/modules/system/tests/modules/twig_theme_test/templates/twig_theme_test.filter.html.twig b/core/modules/system/tests/modules/twig_theme_test/templates/twig_theme_test.filter.html.twig index 28e5c15..cc7bc56 100644 --- a/core/modules/system/tests/modules/twig_theme_test/templates/twig_theme_test.filter.html.twig +++ b/core/modules/system/tests/modules/twig_theme_test/templates/twig_theme_test.filter.html.twig @@ -20,3 +20,4 @@
Without string attribute.
Without either nor class attributes.
All attributes again.
+
ID and class. Having the same ID twice is not valid markup but we want to make sure the filter doesn't use drupal_html_id().