W3cubDocs

/Drupal 8

public function 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;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Template!Attribute.php/function/Attribute::removeClass/8.1.x