$input = 'Some Text Here!'; $output = \Drupal\Component\Utility\Html::cleanCssIdentifier($input); // output: 'Some-Text-Here'
$node_title = $node->getTitle(); $classes[] = 'node-' . \Drupal\Component\Utility\Html::cleanCssIdentifier($node_title); // result: 'node-my-article'In both examples, the `cleanCssIdentifier` function is used to sanitize a string and create a valid CSS identifier that can be used in HTML and CSS. This utility function is part of the Drupal Core library, which provides a set of common functions and classes for building Drupal modules and themes.