diff --git a/core/lib/Drupal/Core/Template/TwigExtension.php b/core/lib/Drupal/Core/Template/TwigExtension.php
index 05c739035cbcf1f83e383c24b710b4000ae7541b..cf3500e39b6eb2feb3f8770d41ecc875c69ac7d6 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 c22be7f0109c54086fd69f8d1e82a00584abcdf4..5665a4c029b54436d26eeb8545451ab9ad581df0 100644
--- a/core/modules/system/src/Tests/Theme/TwigFilterTest.php
+++ b/core/modules/system/src/Tests/Theme/TwigFilterTest.php
@@ -104,13 +104,17 @@ public function testTwigWithoutFilter() {
'message' => 'Without string attribute in the front.',
),
array(
- 'expected' => '
Without either nor class attributes.
',
- 'message' => 'Attributes printed without id nor class attributes.',
+ 'expected' => 'Without id and class attributes.
',
+ 'message' => 'Attributes printed without id and class attributes.',
),
array(
'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 28e5c151f6f6c914fbd7d0527f7f013fbd2738c4..56fc3f11b86c6a562b23f537ed767f254b69c5f7 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
@@ -18,5 +18,6 @@
Class attributes only:
Without boolean attribute.
Without string attribute.
-Without either nor class attributes.
+Without id and 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().