function template_preprocess_views_view in Views (for Drupal 7) 6.3
Same name and namespace in other branches
- 8.3 theme/theme.inc \template_preprocess_views_view()
- 6.2 theme/theme.inc \template_preprocess_views_view()
- 7.3 theme/theme.inc \template_preprocess_views_view()
Preprocess the primary theme implementation for a view.
File
Code
function template_preprocess_views_view(&$vars) {
global $base_path;
$view = $vars['view'];
$vars['rows'] = !empty($view->result) || $view->style_plugin
->even_empty() ? $view->style_plugin
->render($view->result) : '';
$vars['css_name'] = views_css_safe($view->name);
$vars['name'] = $view->name;
$vars['display_id'] = $view->current_display;
// Basic classes
$vars['css_class'] = '';
$vars['classes_array'] = array();
$vars['classes_array'][] = 'view';
$vars['classes_array'][] = 'view-' . views_css_safe($vars['name']);
$vars['classes_array'][] = 'view-id-' . $vars['name'];
$vars['classes_array'][] = 'view-display-id-' . $vars['display_id'];
$css_class = $view->display_handler
->get_option('css_class');
if (!empty($css_class)) {
$vars['css_class'] = preg_replace('/[^a-zA-Z0-9- ]/', '-', $css_class);
$vars['classes_array'][] = $vars['css_class'];
}
$empty = empty($vars['rows']);
$vars['header'] = $view->display_handler
->render_area('header', $empty);
$vars['footer'] = $view->display_handler
->render_area('footer', $empty);
if ($empty) {
$vars['empty'] = $view->display_handler
->render_area('empty', $empty);
}
$vars['exposed'] = !empty($view->exposed_widgets) ? $view->exposed_widgets : '';
$vars['more'] = $view->display_handler
->render_more_link();
$vars['feed_icon'] = !empty($view->feed_icon) ? $view->feed_icon : '';
$vars['pager'] = '';
if ($view->display_handler
->render_pager()) {
$exposed_input = isset($view->exposed_raw_input) ? $view->exposed_raw_input : NULL;
$vars['pager'] = $view->query
->render_pager($exposed_input);
}
$vars['attachment_before'] = !empty($view->attachment_before) ? $view->attachment_before : '';
$vars['attachment_after'] = !empty($view->attachment_after) ? $view->attachment_after : '';
// if administrator, add some links. These used to be tabs, but this is better.
if (user_access('administer views') && module_exists('views_ui') && empty($view->hide_admin_links) && !variable_get('views_no_hover_links', FALSE)) {
$vars['admin_links_raw'] = array(
array(
'title' => t('Edit view'),
'alt' => t("Edit this view"),
'href' => "admin/build/views/edit/{$view->name}",
'fragment' => 'views-tab-' . $view->current_display,
'query' => drupal_get_destination(),
),
);
drupal_alter('views_admin_links', $vars['admin_links_raw'], $view);
$vars['admin_links'] = theme('links', $vars['admin_links_raw']);
}
else {
$vars['admin_links'] = '';
$vars['admin_links_raw'] = array();
}
// Our JavaScript needs to have some means to find the HTML belonging to this
// view.
//
// It is true that the DIV wrapper has classes denoting the name of the view
// and its display ID, but this is not enough to unequivocally match a view
// with its HTML, because one view may appear several times on the page. So
// we set up a hash with the current time, $dom_id, to issue a "unique" identifier for
// each view. This identifier is written to both Drupal.settings and the DIV
// wrapper.
$vars['dom_id'] = !empty($view->dom_id) ? $view->dom_id : md5($view->name . time() . rand());
$vars['classes_array'][] = 'view-dom-id-' . $vars['dom_id'];
// If using AJAX, send identifying data about this view.
if ($view->use_ajax) {
$settings = array(
'views' => array(
'ajax_path' => url('views/ajax'),
'ajaxViews' => array(
'views_dom_id:' . $vars['dom_id'] => array(
'view_name' => $view->name,
'view_display_id' => $view->current_display,
'view_args' => check_plain(implode('/', $view->args)),
'view_path' => check_plain($_GET['q']),
// Pass through URL to ensure we get e.g. language prefixes.
// 'view_base_path' => isset($view->display['page']) ? substr(url($view->display['page']->display_options['path']), strlen($base_path)) : '',
'view_base_path' => $view
->get_path(),
'view_dom_id' => $vars['dom_id'],
// To fit multiple views on a page, the programmer may have
// overridden the display's pager_element.
'pager_element' => isset($view->query->pager) ? $view->query->pager
->get_pager_id() : 0,
),
),
),
);
drupal_add_js($settings, 'setting');
views_add_js('ajax_view');
}
// Flatten the classes to a string for the template file.
$vars['classes'] = implode(' ', $vars['classes_array']);
// If form fields were found in the View, reformat the View output as a form.
if (views_view_has_form_elements($view)) {
$vars['rows'] = drupal_get_form(views_form_id($view), $view, $vars['rows']);
// The form is requesting that all non-essential views elements be hidden,
// usually because the rendered step is not a view result.
if ($view->show_view_elements == FALSE) {
$vars['header'] = '';
$vars['exposed'] = '';
$vars['pager'] = '';
$vars['footer'] = '';
$vars['more'] = '';
$vars['feed_icon'] = '';
}
}
}