function theme_views_view_VIEWNAME($view, $type, $nodes, $level = NULL, $args = NULL);- When Views attempts to display a view, first it attempts to call theme('views_view_VIEWNAME'). If this function does not exist, then it will call theme('views_view'), which is the default method of displaying a view. As a themer, you can override either one, but in general it's better to override the specific one.
The $view argument will be the full definition of the view from the database.
The $type argument will be either 'block', 'page' or 'embed'. (It can actually be other things, but anything else will be user defined. More on this later). This argument is used to control whether page or block specific display is done.
The $nodes argument will be an array with all of the information from the database nicely loaded.
if $level is set to a positive value, this means the view is a summary view, and should be sent to the summary theme instead of the normal type theme.
/**
* Display a view.
*/
function theme_views_view($view, $type, $nodes, $level = NULL, $args = NULL) {
$num_nodes = count($nodes);
if ($type == 'page') {
drupal_set_title(filter_xss_admin(views_get_title($view, 'page')));
views_set_breadcrumb($view);
}
if ($num_nodes) {
$output .= views_get_textarea($view, $type, 'header');
}
if ($type != 'block' && $view->exposed_filter) {
$output .= views_theme('views_display_filters', $view);
}
$plugins = _views_get_style_plugins();
$view_type = ($type == 'block') ? $view->block_type : $view->page_type;
if ($num_nodes || $plugins[$view_type]['even_empty']) {
if ($level !== NULL) {
$output .= "';
}
else {
$output .= "';
}
$output .= views_get_textarea($view, $type, 'footer');
if ($type == 'block' && $view->block_more && $num_nodes >= $view->nodes_per_block) {
$output .= theme('views_more', $view->real_url);
}
}
else {
$output .= views_get_textarea($view, $type, 'empty');
}
if ($view->use_pager) {
$output .= theme('pager', '', $view->pager_limit, $view->use_pager - 1);
}
if ($output) {
$output = "\n";
}
return $output;
}
?> function theme_views_summary_VIEWNAME($view, $type, $level, $nodes, $args);- If a given view has a summary mode -- in which a listing of possible choices for arguments are given -- theme('views_view_summary_VIEWNAME') will be called instead. This is a very good choice to override, because views doesn't really give the admin many options for how to display this, and there are many different possibilities.
$view contains the database view information.
$type contains the same information as theme_views_view().
$level is a number stating which argument this summary is for, starting from 0. If a view has multiple arguments (for example, view/archive/year/month/day) the summary could be for the year (0), the month (1) or the day (2).
$nodes will be an array of database information for the summary.
$args will be the arguments actually present; in the above example will be an empty array if $level = 0, but will contain the year if $level = 1 and the year and the month if $level = 2.
/**
* Display a summary version of a view.
*/
function theme_views_summary($view, $type, $level, $nodes, $args) {
foreach ($nodes as $node) {
$items[] = views_get_summary_link($view->argument[$level]['type'], $node, $view->real_url) . " (" . $node->num_nodes . ")";
}
if ($items) {
$output .= theme('item_list', $items);
}
return $output;
}
?> function theme_views_more($name);- This simple theme function formats the 'more' link.
/**
* Format the 'more' link for a view. Personally I prefer [More] but I've
* been convinced to go with simply 'more'.
*/
function theme_views_more($url) {
return "" . l(t('more'), $url) . "";
}
?> function theme_views_handle_field_TABLENAME_FIELDNAME($fields, $field, $data);- You can theme each piece of individual data by overriding this theme function. Do so with care, as using it properly requires understanding what the data you're receiving is.
/**
* Themeable function to handle displaying a specific field.
*/
function theme_views_handle_field($fields, $field, $data) {
$info = $fields[$field['fullname']];
if ($field['handler'] && function_exists($field['handler'])) {
return $field['handler']($info, $field, $data->$field['queryname'], $data);
}
if ($info['handler'] && is_string($info['handler']) && function_exists($info['handler'])) {
return $info['handler']($info, $field, $data->$field['queryname'], $data);
}
return check_plain($data->$field['queryname']);
}
?> function theme_views_filters_VIEWNAME($form)- For 4.7: This theme function lets you change how the exposed filters are displayed.
function theme_views_filters($form) {
$view = $form['view']['#value'];
foreach ($view->exposed_filter as $count => $expose) {
$row[] = form_render($form["op$count"]) . form_render($form["filter$count"]);
$label[] = $expose['label'];
}
$row[] = form_render($form['submit']);
$label[] = ''; // so the column count is the same.
return theme('table', $label, array($row)) . form_render($form);
}
?> - For 5.x: This theme function lets you change how the exposed filters are displayed.
function theme_views_filters($form) {
$view = $form['view']['#value'];
foreach ($view->exposed_filter as $count => $expose) {
$row[] = drupal_render($form["op$count"]) . drupal_render($form["filter$count"]);
$label[] = $expose['label'];
}
$row[] = drupal_render($form['submit']);
$label[] = ''; // so the column count is the same.
// make the 'q' come first
return drupal_render($form['q']) . theme('table', $label, array($row)) . drupal_render($form);
}
?>
The savvy reader will note that a large section of this documentation has, in fact, disappeared. Most of it was rendered irrelevant by the compartmentalization of the theming functions. It is the author's hope that the code snippets will be sufficient to guide you into what needs to be done, and that later tutorials can provide more interesting information.
http://drupal.org/node/42597Ref:
No comments:
Post a Comment