You are here

function template_preprocess_semanticviews_style in Semantic Views 8.2

Display the simple view of rows one after another.

File

./semanticviews.module, line 50
Semantic Views module file.

Code

function template_preprocess_semanticviews_style(&$vars) {
  $view = $vars['view'];
  $options = $view->style_plugin->options;
  $last_every_nth = $options['row']['last_every_nth'];
  $vars['group']['element'] = $options['group']['element_type'];
  $vars['group']['attributes'] = new Attribute();
  foreach (semanticviews_extract_attributes($options['group']['attributes']) as $key => $value) {
    $vars['group']['attributes']
      ->setAttribute($key, $value);
  }
  $vars['list']['element'] = $options['list']['element_type'];
  $vars['list']['attributes'] = new Attribute();
  foreach (semanticviews_extract_attributes($options['list']['attributes']) as $key => $value) {
    $vars['list']['attributes']
      ->setAttribute($key, $value);
  }

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

  // When grouping fields row index doesn't reset in each group,
  // so we have to do it manually.
  // Otherwise "last_every_nth" may work incorrect.
  $index_in_group = 0;
  foreach ($vars['rows'] as $id => $row) {
    $vars['rows'][$id] = [];
    $vars['rows'][$id]['content'] = $row;
    $vars['rows'][$id]['element'] = $options['row']['element_type'];
    $vars['rows'][$id]['attributes'] = new Attribute();
    foreach (semanticviews_extract_attributes($options['row']['attributes']) as $key => $value) {
      $value = $view->style_plugin
        ->tokenizeValue($value, $id);
      $vars['rows'][$id]['attributes']
        ->setAttribute($key, $value);
    }
    if ($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 && $index_in_group % $last_every_nth == 0 || !$last_every_nth && $index_in_group == 0) {
        if ($class = $view->style_plugin
          ->tokenizeValue($options['row']['first_class'], $id)) {
          $vars['rows'][$id]['attributes']
            ->addClass($class);
        }
      }
    }
    if ($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 && ($index_in_group + 1) % $last_every_nth == 0 || !$last_every_nth && $index_in_group + 1 == count($vars['rows'])) {
        if ($class = $view->style_plugin
          ->tokenizeValue($options['row']['last_class'], $id)) {
          $vars['rows'][$id]['attributes']
            ->addClass($class);
        }
      }
    }
    if ($striping) {
      if ($class = $view->style_plugin
        ->tokenizeValue($stripes[$id % $striping], $id)) {
        $vars['rows'][$id]['attributes']
          ->addClass($class);
      }
    }
    $index_in_group++;
  }
}