Attribute::removeClass

public 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 244

Class

Attribute
Collects, sanitizes, and renders HTML attributes.

Namespace

Drupal\Core\Template

Code

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 = array();
    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;
}
doc_Drupal
2016-10-29 08:45:03
Comments
Leave a Comment

Please login to continue.