You are here

function template_preprocess_views_rows_wrapper in Views Rows Wrapper 7

Same name and namespace in other branches
  1. 8.2 views_rows_wrapper.theme.inc \template_preprocess_views_rows_wrapper()
  2. 8 views_rows_wrapper.theme.inc \template_preprocess_views_rows_wrapper()

Implements hook_preprocess_HOOK() for theme_views_rows_wrapper().

@inheritdoc

File

./views_rows_wrapper.module, line 48
Views Rows Wrapper module.

Code

function template_preprocess_views_rows_wrapper(&$vars) {
  $view = $vars['view'];
  $rows = $vars['rows'];
  $style = $view->style_plugin;
  $options = $style->options;
  $element_types = views_rows_wrapper_element_types();
  $attribute_types = views_rows_wrapper_attribute_types();
  $use_wrapper = isset($options['use_wrapper']) ? $options['use_wrapper'] : FALSE;
  $element_type = isset($options['element_type']) ? $element_types[$options['element_type']] : $element_types[0];
  $element_type = strtolower($element_type);
  $attribute_type = isset($options['attribute_type']) ? $attribute_types[$options['attribute_type']] : $attribute_types[0];
  $attribute_type = strtolower($attribute_type);
  $attribute_name = isset($options['attribute_name']) ? $options['attribute_name'] : '';
  $attribute_name = preg_replace('/[^a-zA-Z0-9-_\\s]/', '', $attribute_name);
  $rows_number = isset($options['rows_number']) ? $options['rows_number'] : 2;
  $wrap_method = isset($options['wrap_method']) ? $options['wrap_method'] : 1;
  $default_rows = isset($options['default_rows']) ? $options['default_rows'] : FALSE;
  $strip_rows = isset($options['strip_rows']) ? $options['strip_rows'] : FALSE;
  $count = 0;
  $k = 0;
  $max = count($rows);
  $is_wrapped_once = FALSE;
  foreach ($rows as $row) {
    $classes = array();
    $count++;
    $k++;
    if ($default_rows) {
      $classes[] = 'views-row';
      $classes[] = 'views-row-' . $count;
    }
    if ($strip_rows) {
      $classes[] = 'views-row-' . ($count % 2 ? 'odd' : 'even');
      if ($count == 1) {
        $classes[] = 'views-row-first';
      }
      if ($count == $max) {
        $classes[] = 'views-row-last';
      }
    }
    if ($default_rows || $strip_rows) {
      $class = implode(" ", $classes);
      $row = '<div class="' . $class . '">' . $row . '</div>';
    }
    if ($use_wrapper && !$is_wrapped_once) {
      if ($k == 1) {
        $row = '<' . $element_type . ' ' . $attribute_type . '="' . $attribute_name . '">' . $row;
      }
      if ($count % $rows_number == 0 || $count == $max && $k < $rows_number) {
        $row = $row . '</' . $element_type . '>';
      }
    }
    if ($k >= $rows_number) {
      $k = 0;
      if ($wrap_method == 1) {
        $is_wrapped_once = TRUE;
      }
    }
    $vars['rows_wrapped'][] = $row;
  }
}