public function Attribute::removeClass in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Template/Attribute.php \Drupal\Core\Template\Attribute::removeClass()
- 9 core/lib/Drupal/Core/Template/Attribute.php \Drupal\Core\Template\Attribute::removeClass()
Removes argument values from array of existing CSS classes.
Parameters
string|array ...: CSS classes to remove from the class attribute array.
Return value
$this
File
- core/
lib/ Drupal/ Core/ Template/ Attribute.php, line 265
Class
- Attribute
- Collects, sanitizes, and renders HTML attributes.
Namespace
Drupal\Core\TemplateCode
public function removeClass() {
// With no class attribute, there is no need to remove.
if (isset($this->storage['class']) && $this->storage['class'] instanceof AttributeArray) {
$args = func_get_args();
$classes = [];
foreach ($args as $arg) {
// Merge the values passed in from the classes array.
// The argument is cast to an array to support comma separated single
// values or one or more array arguments.
$classes = array_merge($classes, (array) $arg);
}
// Remove the values passed in from the value array. Use array_values() to
// ensure that the array index remains sequential.
$classes = array_values(array_diff($this->storage['class']
->value(), $classes));
$this->storage['class']
->exchangeArray($classes);
}
return $this;
}