function views_ajax_form_wrapper
3.x ajax.inc | views_ajax_form_wrapper($form_id, &$form_state) |
2.x ajax.inc | views_ajax_form_wrapper($form_id, &$form_state) |
Wrapper around drupal_build_form to handle some AJAX stuff automatically. This makes some assumptions about the client.
Related topics
5 calls to views_ajax_form_wrapper()
- views_ui_add_display in includes/
admin.inc - AJAX callback to add a display.
- views_ui_ajax_form in includes/
admin.inc - Generic entry point to handle forms.
- views_ui_analyze_view in includes/
admin.inc - Page callback to display analysis information on a view.
- views_ui_clone_display in includes/
admin.inc - AJAX callback to add a display.
- views_ui_edit_details in includes/
admin.inc - Page callback to edit details of a view.
File
Code
function views_ajax_form_wrapper($form_id, &$form_state) {
// This won't override settings already in.
$form_state += array(
'rerender' => FALSE,
'no_redirect' => !empty($form_state['ajax']),
);
$output = drupal_build_form($form_id, $form_state);
if (!empty($form_state['ajax']) && empty($form_state['executed'])) {
// If the form didn't execute and we're using ajax, build up a
// json command object to render.
$object = new stdClass();
$object->display = '';
if ($messages = theme('status_messages')) {
$object->display = '<div class="views-messages">' . $messages . '</div>';
}
$object->display .= $output;
$object->title = empty($form_state['title']) ? '' : $form_state['title'];
if (!empty($form_state['help_topic'])) {
$module = !empty($form_state['help_module']) ? $form_state['help_module'] : 'views';
$object->title = theme('advanced_help_topic', $module, $form_state['help_topic']) . $object->title;
}
$object->url = empty($form_state['url']) ? url($_GET['q'], array('absolute' => TRUE)) : $form_state['url'];
$object->js = empty($form_state['js settings']) ? NULL : $form_state['js settings'];
if (!empty($form_state['#section'])) {
$object->hilite = '.' . views_ui_item_css($form_state['#section']);
}
$output = $object;
}
// These forms have the title built in, so set the title here:
if (empty($form_state['ajax']) && !empty($form_state['title'])) {
drupal_set_title($form_state['title']);
}
return $output;
}