function Html::getClass

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Component/Utility/Html.php \Drupal\Component\Utility\Html::getClass()
  2. 8.9.x core/lib/Drupal/Component/Utility/Html.php \Drupal\Component\Utility\Html::getClass()
  3. 11.x core/lib/Drupal/Component/Utility/Html.php \Drupal\Component\Utility\Html::getClass()

Prepares a string for use as a valid class name.

Do not pass one string containing multiple classes as they will be incorrectly concatenated with dashes, i.e. "one two" will become "one-two".

Parameters

mixed $class: The class name to clean. It can be a string or anything that can be cast to string.

Return value

string The cleaned class name.

4 calls to Html::getClass()
FormBuilder::retrieveForm in core/lib/Drupal/Core/Form/FormBuilder.php
Retrieves the structured array that defines a given form.
HtmlTest::testHtmlClass in core/tests/Drupal/Tests/Component/Utility/HtmlTest.php
Tests that Html::getClass() cleans the class name properly.
SvgIconBuilder::buildRenderArray in core/lib/Drupal/Core/Layout/Icon/SvgIconBuilder.php
Builds a render array representation of an SVG.
WidgetBase::form in core/lib/Drupal/Core/Field/WidgetBase.php
Creates a form element for a field.

File

core/lib/Drupal/Component/Utility/Html.php, line 74

Class

Html
Provides DOMDocument helpers for parsing and serializing HTML strings.

Namespace

Drupal\Component\Utility

Code

public static function getClass($class) {
  $class = (string) $class;
  if (!isset(static::$classes[$class])) {
    static::$classes[$class] = static::cleanCssIdentifier(mb_strtolower($class));
  }
  return static::$classes[$class];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.