Issue #2837013 by benjifisher, leslieg, alexpott: clean_class Twig filter does not work with Views rewriting

8.4.x
Lauri Eskola 2017-04-27 22:05:35 +03:00
parent 10db66234a
commit d2a5fe79e2
2 changed files with 20 additions and 3 deletions

View File

@ -61,13 +61,15 @@ class Html {
* Do not pass one string containing multiple classes as they will be
* incorrectly concatenated with dashes, i.e. "one two" will become "one-two".
*
* @param string $class
* The class name to clean.
* @param mixed $class
* The class name to clean. It can be a string or anything that can be cast
* to string.
*
* @return string
* The cleaned class name.
*/
public static function getClass($class) {
$class = (string) $class;
if (!isset(static::$classes[$class])) {
static::$classes[$class] = static::cleanCssIdentifier(Unicode::strtolower($class));
}

View File

@ -2,6 +2,8 @@
namespace Drupal\Tests\Component\Utility;
use Drupal\Component\Render\MarkupInterface;
use Drupal\Component\Render\MarkupTrait;
use Drupal\Component\Utility\Html;
use Drupal\Tests\UnitTestCase;
@ -87,7 +89,12 @@ class HtmlTest extends UnitTestCase {
*/
public function testHtmlClass() {
// Verify Drupal coding standards are enforced.
$this->assertSame(Html::getClass('CLASS NAME_[Ü]'), 'class-name--ü', 'Enforce Drupal coding standards.');
$this->assertSame('class-name--ü', Html::getClass('CLASS NAME_[Ü]'), 'Enforce Drupal coding standards.');
// Test Html::getClass() handles Drupal\Component\Render\MarkupInterface
// input.
$markup = HtmlTestMarkup::create('CLASS_FROM_OBJECT');
$this->assertSame('class-from-object', Html::getClass($markup), 'Markup object is converted to CSS class.');
}
/**
@ -390,3 +397,11 @@ class HtmlTest extends UnitTestCase {
}
}
/**
* Marks an object's __toString() method as returning markup.
*/
class HtmlTestMarkup implements MarkupInterface {
use MarkupTrait;
}