You are here

function template_preprocess_semanticviews_view_unformatted in Semantic Views 6

Same name and namespace in other branches
  1. 7 semanticviews.theme.inc \template_preprocess_semanticviews_view_unformatted()

Display the simple view of rows one after another

File

./semanticviews.theme.inc, line 71
semanticviews.theme.inc TODO: Enter file description here.

Code

function template_preprocess_semanticviews_view_unformatted(&$vars) {
  $view = $vars['view'];
  $vars['group_element'] = check_plain($vars['options']['group']['element_type']);
  $vars['group_attributes'] = array();
  if ($vars['options']['group']['class']) {
    $vars['group_attributes']['class'] = $vars['options']['group']['class'];
  }
  $vars['list_element'] = check_plain($vars['options']['list']['element_type']);
  $vars['list_attributes'] = array();
  if ($vars['options']['list']['class']) {
    $vars['list_attributes']['class'] = $vars['options']['list']['class'];
  }

  // TODO: set a default or handle empty value.
  $vars['row_element'] = check_plain($vars['options']['row']['element_type']);
  $last_every_nth = $vars['options']['row']['last_every_nth'];
  $vars['row_attributes'] = array();

  // Set up striping class array.
  $stripes = array();
  if (trim($vars['options']['row']['striping_classes'])) {
    $stripes = explode(' ', trim($vars['options']['row']['striping_classes']));
  }
  $striping = count($stripes);

  // Get alias tokens.
  $tokens = semanticviews_get_alias_tokens($view);
  foreach ($vars['rows'] as $id => $row) {

    // Get token replacements.
    $replacements = semanticviews_get_token_replacements($view->result[$id], $tokens);

    // Add replacement for the row number.
    $replacements['#'] = $id;
    $vars['row_attributes'][$id] = array();
    $classes = array();
    if ($vars['options']['row']['class']) {
      $classes[] = strtr($vars['options']['row']['class'], $replacements);
    }
    if ($vars['options']['row']['first_class']) {

      // The FIRST class attribute can be used in two ways. When the "last every
      // nth" option is specified, the FIRST attribute is added to the class in
      // those intervals. This could be useful for grid designs where the first
      // unit in a row needs a zero width margin.
      if ($last_every_nth && $id % $last_every_nth == 0 || !$last_every_nth && $id == 0) {
        $classes[] = strtr($vars['options']['row']['first_class'], $replacements);
      }
    }
    if ($vars['options']['row']['last_class']) {

      // The LAST class attribute can be used in two ways. When the "last every
      // nth" option is specified, the LAST attribute is added to the class in
      // those intervals. This could be useful for grid designs where the last
      // unit in a row needs a zero width margin.
      if ($last_every_nth && ($id + 1) % $last_every_nth == 0 || !$last_every_nth && $id + 1 == count($vars['rows'])) {
        $classes[] = strtr($vars['options']['row']['last_class'], $replacements);
      }
    }
    if ($striping) {
      $classes[] = strtr($stripes[$id % $striping], $replacements);
    }
    if (!empty($classes)) {
      $vars['row_attributes'][$id]['class'] = implode(' ', $classes);
    }
  }
}