src/Drupal/Core/Template/Attribute.php
public function addClass() {
    $args = func_get_args();
    if ($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);
      }

      // Merge if there are values, just add them otherwise.
      if (isset($this->storage['class']) && $this->storage['class'] instanceof AttributeArray) {
        // Merge the values passed in from the class value array.
        $classes = array_merge($this->storage['class']->value(), $classes);
        $this->storage['class']->exchangeArray($classes);
      }
      else {
        $this->offsetSet('class', $classes);
      }
    }

    return $this;
  }
public function addClass() {
    $args = func_get_args();
    if ($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);
      }

      // Merge if there are values, just add them otherwise.
      if (isset($this->storage['class']) && $this->storage['class'] instanceof AttributeArray) {
        // Merge the values passed in from the class value array.
        $classes = array_merge($this->storage['class']->value(), $classes);
        $this->storage['class']->exchangeArray($classes);
      }
      else {
        $this->offsetSet('class', $classes);
      }
    }

    return $this;
  }
public function addClass ( ) { $ args = func_get_args ( ) ; if ( $ 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 ) ; } // Merge if there are values, just add them otherwise. if ( isset ( $ this -> storage [ 'class' ] ) && $ this -> storage [ 'class' ] instanceof AttributeArray ) { // Merge the values passed in from the class value array. $ classes = array_merge ( $ this -> storage [ 'class' ] -> value ( ) , $ classes ) ; $ this -> storage [ 'class' ] -> exchangeArray ( $ classes ) ; } else { $ this -> offsetSet ( 'class' , $ classes ) ; } } return $ this ; }
Adds classes or merges them on to array of existing CSS classes.

@param string|array ...
CSS classes to add to the class attribute array.

@return $this
Adds classes or merges them on to array of existing CSS classes .