function template_preprocess_views_view_unformatted

Prepares variables for views unformatted rows templates.

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

Parameters

array $vars: An associative array containing:

  • view: The view object.
  • rows: An array of row items. Each row is an array of content.
1 call to template_preprocess_views_view_unformatted()
template_preprocess_views_view_list in drupal/core/modules/views/views.theme.inc
Prepares variables for Views HTML list templates.

File

drupal/core/modules/views/views.theme.inc, line 887
Preprocessors and helper functions to make theming easier.

Code

function template_preprocess_views_view_unformatted(&$vars) {
  $view = $vars['view'];
  $rows = $vars['rows'];
  $style = $view->style_plugin;
  $options = $style->options;
  $vars['row_classes'] = array();
  $vars['classes'] = array();
  $default_row_class = isset($options['default_row_class']) ? $options['default_row_class'] : FALSE;
  $row_class_special = isset($options['row_class_special']) ? $options['row_class_special'] : FALSE;

  // Set up striping values.
  $count = 0;
  $max = count($rows);
  foreach ($rows as $id => $row) {
    $vars['row_classes'][$id] = array();
    $count++;
    if ($default_row_class) {
      $vars['row_classes'][$id]['class'][] = 'views-row';
      $vars['row_classes'][$id]['class'][] = 'views-row-' . $count;
    }
    if ($row_class_special) {
      $vars['row_classes'][$id]['class'][] = 'views-row-' . ($count % 2 ? 'odd' : 'even');
      if ($count == 1) {
        $vars['row_classes'][$id]['class'][] = 'views-row-first';
      }
      if ($count == $max) {
        $vars['row_classes'][$id]['class'][] = 'views-row-last';
      }
    }
    if ($row_class = $view->style_plugin
      ->getRowClass($id)) {
      $vars['row_classes'][$id]['class'][] = $row_class;
    }
    $vars['row_classes'][$id] = new Attribute($vars['row_classes'][$id]);
  }
}