You are here

public function AlphaPagination::addClasses in Views Alpha Pagination 8.2

Add classes to an attributes array from a view option.

Parameters

string[]|string $classes: An array of classes or a string of classes.

array $attributes: An attributes array to add the classes to, passed by reference.

Return value

array An array of classes to be used in a render array.

File

src/AlphaPagination.php, line 163

Class

AlphaPagination
A base views handler for alpha pagination.

Namespace

Drupal\alpha_pagination

Code

public function addClasses($classes, array &$attributes) {
  $processed = [];

  // Sanitize any classes provided for the item list.
  foreach ((array) $classes as $v) {
    foreach (array_filter(explode(' ', $v)) as $vv) {
      $processed[] = Html::cleanCssIdentifier($vv);
    }
  }

  // Don't add any classes if it's empty, which will add an empty attribute.
  if ($processed) {
    if (!isset($attributes['class'])) {
      $attributes['class'] = [];
    }
    $attributes['class'] = array_unique(array_merge($attributes['class'], $processed));
  }
  return $classes;
}