function ViewsThemeHooks::preprocessViewsViewList

Prepares variables for Views HTML list templates.

Default template: views-view-list.html.twig.

Parameters

array $variables: An associative array containing:

  • view: A View object.

File

core/modules/views/src/Hook/ViewsThemeHooks.php, line 1091

Class

ViewsThemeHooks
Hook implementations for views.

Namespace

Drupal\views\Hook

Code

public function preprocessViewsViewList(array &$variables) : void {
  $handler = $variables['view']->style_plugin;
  // Fetch classes from handler options.
  $variables['list']['attributes'] = new Attribute();
  if ($handler->options['class']) {
    $class = explode(' ', $handler->options['class']);
    $class = array_map('\\Drupal\\Component\\Utility\\Html::cleanCssIdentifier', $class);
    // Initialize a new attribute class for $class.
    $variables['list']['attributes']->addClass($class);
  }
  $type = $handler->options['type'];
  if ($type === 'ol') {
    $pager = $variables['view']->getPager();
    $variables['list']['attributes']['start'] = $variables['view']->getCurrentPage() * $pager->options['items_per_page'] + 1;
  }
  // Fetch wrapper classes from handler options.
  if ($handler->options['wrapper_class']) {
    $wrapper_class = explode(' ', $handler->options['wrapper_class']);
    $variables['attributes']['class'] = array_map('\\Drupal\\Component\\Utility\\Html::cleanCssIdentifier', $wrapper_class);
  }
  $variables['list']['type'] = $type;
  $this->preprocessViewsViewUnformatted($variables);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.