Issue #2837013 by benjifisher, leslieg, alexpott: clean_class Twig filter does not work with Views rewriting
parent
10db66234a
commit
d2a5fe79e2
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue