Commit 3f3fc8db authored by alexpott's avatar alexpott

Issue #2283301 by Dave Reid, davidhernandez, Cottser, joelpittet: Added Twig...

Issue #2283301 by Dave Reid, davidhernandez, Cottser, joelpittet: Added Twig filters for drupal_html_class() and drupal_clean_id_identifier().
parent b366d7d7
......@@ -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'),
);
}
......
......@@ -104,13 +104,17 @@ public function testTwigWithoutFilter() {
'message' => 'Without string attribute in the front.',
),
array(
'expected' => '<div><span checked>Without either nor class attributes.</span></div>',
'message' => 'Attributes printed without id nor class attributes.',
'expected' => '<div><span checked>Without id and class attributes.</span></div>',
'message' => 'Attributes printed without id and class attributes.',
),
array(
'expected' => '<div><span id="quotes" checked class="red green blue">All attributes again.</span></div>',
'message' => 'All attributes printed again.',
),
array(
'expected' => '<div id="quotes-here"><span class="gray-like-a-bunny bem__ized--top-feature" id="quotes-here">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().</span></div>',
'message' => 'Class and ID filtered.',
),
);
foreach ($elements as $element) {
......
......@@ -18,5 +18,6 @@
<div><span class="{{ attributes.class }}">Class attributes only:</span></div>
<div><span {{ attributes.checked }}{{ attributes|without('checked') }}>Without boolean attribute.</span></div>
<div><span data-id="{{ attributes.id }}"{{ attributes|without('id') }}>Without string attribute.</span></div>
<div><span{{ attributes|without('id', 'class') }}>Without either nor class attributes.</span></div>
<div><span{{ attributes|without('id', 'class') }}>Without id and class attributes.</span></div>
<div><span{{ attributes }}>All attributes again.</span></div>
<div id="{{ 'quotes Here!'|clean_id }}"><span class="{{ 'Gray like a bunny!'|clean_class }} {{ 'BEM__ized--Top Feature'|clean_class }}" id="{{ 'quotes Here!'|clean_id }}">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().</span></div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment