You are here

function template_preprocess_semanticviews_view_fields in Semantic Views 6

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

Preprocess theme function to print a single record from a row, with fields

File

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

Code

function template_preprocess_semanticviews_view_fields(&$vars) {
  $view = $vars['view'];

  // Loop through the fields for this view.
  $vars['fields'] = array();

  // ensure it's at least an empty array.
  foreach ($view->field as $id => $field) {

    // render this even if set to exclude so it can be used elsewhere.
    $field_output = $view->style_plugin
      ->get_field($view->row_index, $id);
    $empty = $field_output !== 0 && empty($field_output);
    if (empty($field->options['exclude']) && !(($vars['options']['skip_blank'] || $field->options['hide_empty']) && $empty)) {
      $object = new stdClass();
      $object->content = $field_output;
      if (isset($view->field[$id]->field_alias) && isset($vars['row']->{$view->field[$id]->field_alias})) {
        $object->raw = $vars['row']->{$view->field[$id]->field_alias};
      }
      else {
        $object->raw = NULL;

        // make sure it exists to reduce NOTICE
      }
      $object->handler =& $view->field[$id];
      if (isset($vars['options']['semantic_html'][$id])) {
        $semantic_html = $vars['options']['semantic_html'][$id];
      }
      else {

        // Default empty values.
        $semantic_html = array(
          'element_type' => 'div',
          'class' => '',
          'label_element_type' => 'label',
          'label_class' => '',
        );
      }

      // Field content
      $object->element_type = check_plain($semantic_html['element_type']);
      $object->attributes = array();
      if ($semantic_html['class']) {
        $object->attributes['class'] = $semantic_html['class'];
      }

      // Field label
      $object->label = check_plain($view->field[$id]
        ->label());
      if (!empty($object->label)) {
        $object->label_element_type = check_plain($semantic_html['label_element_type']);
        $object->label_attributes = array();
        if ($semantic_html['label_class']) {
          $object->label_attributes['class'] = $semantic_html['label_class'];
        }
      }
      $vars['fields'][$id] = $object;
    }
  }
}