function TwigExtension::addClass
Adds a value into the class attributes of a given element.
Assumes element is an array.
Parameters
array $element: A render element.
string[]|string ...$classes: The class(es) to add to the element. Arguments can include string keys directly, or arrays of string keys.
Return value
array The element with the given class(es) in attributes.
File
-
core/
lib/ Drupal/ Core/ Template/ TwigExtension.php, line 759
Class
- TwigExtension
- A class providing Drupal Twig extensions.
Namespace
Drupal\Core\TemplateCode
public function addClass(array $element, ...$classes) : array {
$attributes = new Attribute($element['#attributes'] ?? []);
$attributes->addClass(...$classes);
$element['#attributes'] = $attributes->toArray();
// Make sure element gets rendered again.
unset($element['#printed']);
return $element;
}