function views_ajax
3.x ajax.inc | views_ajax() |
2.x ajax.inc | views_ajax() |
Menu callback to load a view via AJAX.
Related topics
1 string reference to 'views_ajax'
- views_menu in ./
views.module - Implementation of hook_menu().
File
Code
function views_ajax() {
if (isset($_REQUEST['view_name']) && isset($_REQUEST['view_display_id'])) {
$name = $_REQUEST['view_name'];
$display_id = $_REQUEST['view_display_id'];
$args = isset($_REQUEST['view_args']) && $_REQUEST['view_args'] !== '' ? explode('/', $_REQUEST['view_args']) : array();
$path = isset($_REQUEST['view_path']) ? $_REQUEST['view_path'] : NULL;
$dom_id = isset($_REQUEST['view_dom_id']) ? intval($_REQUEST['view_dom_id']) : NULL;
$pager_element = isset($_REQUEST['pager_element']) ? intval($_REQUEST['pager_element']) : NULL;
views_include('ajax');
$object = new stdClass();
$object->status = FALSE;
$object->display = '';
$arg = explode('/', $_REQUEST['view_path']);
if ($arg[0] == 'admin' || (variable_get('node_admin_theme', '0') && $arg[0] == 'node' && ($arg[1] == 'add' || $arg[2] == 'edit'))) {
global $custom_theme;
$custom_theme = variable_get('admin_theme', '0');
drupal_add_css(drupal_get_path('module', 'system') . '/admin.css', 'module');
}
// Load the view.
if ($view = views_get_view($name)) {
if ($view->access($display_id)) {
// Fix 'q' for paging.
if (!empty($path)) {
$_GET['q'] = $path;
}
// Override the display's pager_element with the one actually used.
if (isset($pager_element)) {
$view->display[$display_id]->handler->set_option('pager_element', $pager_element);
}
// Reuse the same DOM id so it matches that in Drupal.settings.
$view->dom_id = $dom_id;
$object->status = TRUE;
$object->display .= $view->preview($display_id, $args);
// Get the title after the preview call, to let it set
// up both the view's current display and arguments
$object->title = $view->get_title();
// Register the standard JavaScript callback.
$object->__callbacks = array('Drupal.Views.Ajax.ajaxViewResponse');
// Allow other modules to extend the data returned.
drupal_alter('ajax_data', $object, 'views', $view);
}
}
$messages = theme('status_messages');
$object->messages = $messages ? '<div class="views-messages">' . $messages . '</div>' : '';
views_ajax_render($object);
}
}