theme.inc 2.72 KB
Newer Older
1 2 3 4 5 6 7 8 9
<?php
// $Id$

/**
 * Preprocess the primary theme implementation for a view.
 */
function template_preprocess_views_view(&$vars) {
  $view = $vars['view'];

merlinofchaos's avatar
merlinofchaos committed
10
  $vars['rows']       = $view->style_handler->render($view->result);
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
  $vars['css_name']   = views_css_safe($view->name);

  if (!$vars['rows']) {
    $vars['empty']    = $view->display_handler->render_empty();
  }
  else {
    $vars['empty']    = '';
  }

  $vars['filters']    = $view->display_handler->render_filters();
  $vars['header']     = $view->display_handler->render_header();
  $vars['footer']     = $view->display_handler->render_footer();
  $vars['more']       = $view->display_handler->render_more_link();
  $vars['feed_icon']  = $view->display_handler->render_feed_icon();

  $vars['pager']      = '';
merlinofchaos's avatar
merlinofchaos committed
27 28
  if (!empty($view->pager['use_pager'])) {
    $vars['pager']    = theme('pager', array(), $view->pager['items_per_page'], $view->pager['element']);
29 30 31 32 33 34 35
  }

}

/**
 * Preprocess theme function to print a single record from a row, with fields
 */
36
function template_preprocess_views_view_fields(&$vars) {
37 38 39
  $view = $vars['view'];

  // Loop through the fields for this view.
40
  foreach ($view->field as $field) {
41 42 43 44 45 46 47 48 49 50 51 52 53
    if (!empty($field->handler) && is_object($field->handler)) {
      $themes = array(
        'views_view_field__' . $view->name . '__' . $field->handler->field_alias,
        'views_view_field__' . $view->name,
        'views_view_field__' . $field->handler->field_alias,
        'views_view_field',
      );
      // Add the field into a variable named after the field. field_alias will be unique.
      $vars[$field->handler->field_alias] = theme($themes, $view, $field, $vars['row']);
      // Create a second variable so we can easily find what fields we have and what the
      // CSS classes should be.
      $vars['fields'][$field->handler->field_alias] = views_css_safe($field->handler->field_alias);
    }
54 55 56 57 58 59 60 61
  }
}

/**
 * Display a single views field.
 *
 * Interesting bits of info:
 * $field->field_alias says what the raw value in $row will be. Reach it like
62
 * this: @code { $row->{$field->field_alias} @endcode
63 64 65 66
 */
function theme_views_view_field($view, $field, $row) {
  return $field->handler->render($row);
}
67 68 69 70

/**
 * Preprocess theme function to print a single record from a row, with fields
 */
merlinofchaos's avatar
merlinofchaos committed
71
function template_preprocess_views_view_summary(&$vars) {
72 73 74
  $view     = $vars['view'];
  $argument = $view->argument[$view->build_info['summary_level']]->handler;

merlinofchaos's avatar
merlinofchaos committed
75 76 77 78 79
  foreach ($vars['rows'] as $id => $row) {
    $vars['rows'][$id]->link = $argument->summary_name($row);
    $vars['rows'][$id]->url = $argument->summary_link($row, $view->get_url());
    $vars['rows'][$id]->count = intval($row->{$argument->count_alias});
  }
80 81
}

82 83 84
/**
 * @defgroup views_templates Views' template files
 */