function views_ui_ajax_form

3.x admin.inc views_ui_ajax_form($js, $key, $view, $display_id = '')
2.x admin.inc views_ui_ajax_form($js, $key, $view, $display_id)

Generic entry point to handle forms.

We do this for consistency and to make it easy to chain forms together. This only works for forms that use both $view and $display_id, so we have a couple of ajax forms that we don't use with this system.

1 string reference to 'views_ui_ajax_form'

File

includes/admin.inc, line 1601
admin.inc Provides the Views' administrative interface.

Code

function views_ui_ajax_form($js, $key, $view, $display_id) {
  $form = views_ui_ajax_forms($key);
  if (empty($form)) {
    return drupal_not_found();
  }

  views_include('ajax');
  $args = func_get_args();
  // Remove the known args
  array_splice($args, 0, 4);

  $form_state = views_ui_build_form_state($js, $key, $view, $display_id, $args);
  // check to see if this is the top form of the stack. If it is, pop
  // it off; if it isn't, the user clicked somewhere else and the stack is
  // now irrelevant.
  if (!empty($view->stack)) {
    $identifier = views_ui_build_identifier($key, $view, $display_id, $args);
    $top = array_shift($view->stack);
    if (array_shift($top) != $identifier) {
      $view->stack = array();
    }
  }

  $output = views_ajax_form_wrapper($form_state['form_id'], $form_state);

  if (!$output) {
    // Sometimes we need to re-generate the form for multi-step type operations.
    $object = NULL;
    if (!empty($view->stack)) {
      $stack = $view->stack; // copy so the next shift doesn't break the array
      $top = array_shift($stack);
      $top[0] = $js; // change identifier into $js setting
      $stepview = $top[2]; // Change view into a reference [#452384]
      $top[2] = &$stepview;
      $form_state = call_user_func_array('views_ui_build_form_state', $top);
      $form_state['input'] = array(); // this is a new form, make sure it
      // doesn't try to inherit $_POST info.
      if (!$js) {
        return drupal_goto(views_ui_build_form_url($form_state));
      }
      $object = views_ajax_form_wrapper($form_state['form_id'], $form_state);
      $object->url = url(views_ui_build_form_url($form_state));
    }
    else if (!$js) {
      // if nothing on the stack, non-js forms just go back to the main view editor.
      return drupal_goto("admin/build/views/edit/$view->name");
    }
    // regenerate all tabs because changes to the default tab could ripple.
    return views_ui_regenerate_tabs($view, NULL, $object);
  }

  return ($js) ? views_ajax_render($output) : $output;
}