You are here

function views_ui_add_display in Views (for Drupal 7) 6.3

Same name and namespace in other branches
  1. 6.2 includes/admin.inc \views_ui_add_display()

AJAX callback to add a display.

1 string reference to 'views_ui_add_display'
views_ui_menu in ./views_ui.module

File

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

Code

function views_ui_add_display($js, $view) {
  views_include('ajax');
  $form_state = array(
    'view' => &$view,
    'ajax' => $js,
  );
  $output = views_ajax_form_wrapper('views_ui_add_display_form', $form_state);
  if ($js) {

    // If we don't have an output object, it was submitted. Set up the submission.
    if (empty($output)) {
      $id = $form_state['id'];

      // Make sure the new display is active
      if (!$view
        ->set_display('default')) {
        views_ajax_render(t('Unable to initialize default display'));
      }

      // Render the new display
      list($title, $body) = views_ui_display_tab($view, $view->display[$id]);

      // Instruct the javascript on the browser to render the new tab.
      $output = new stdClass();
      $output->tab = array(
        '#views-tab-' . $id => array(
          'title' => $title,
          'body' => $body,
        ),
      );
    }

    // Render the command object. This automatically exits.
    views_ajax_render($output);
  }

  // But the non-js variant will return output if it didn't redirect us.
  return $output;
}