You are here

function panels_renderer_editor::ajax_add_pane in Panels 6.3

Same name and namespace in other branches
  1. 7.3 plugins/display_renderers/panels_renderer_editor.class.php \panels_renderer_editor::ajax_add_pane()

AJAX entry point to add a new pane.

File

plugins/display_renderers/panels_renderer_editor.class.php, line 698
Class file to control the main Panels editor.

Class

panels_renderer_editor
@file Class file to control the main Panels editor.

Code

function ajax_add_pane($region = NULL, $type_name = NULL, $subtype_name = NULL, $step = NULL) {
  $content_type = ctools_get_content_type($type_name);
  $subtype = ctools_content_get_subtype($content_type, $subtype_name);
  if (!isset($step) || !isset($this->cache->new_pane)) {
    $pane = panels_new_pane($type_name, $subtype_name, TRUE);
    $this->cache->new_pane =& $pane;
  }
  else {
    $pane =& $this->cache->new_pane;
  }
  $form_state = array(
    'display' => &$this->cache->display,
    'contexts' => $this->cache->display->context,
    'pane' => &$pane,
    'cache_key' => $this->display->cache_key,
    'cache' => &$this->cache,
    'ajax' => TRUE,
    'modal' => TRUE,
    // This will force the system to not automatically render.
    'modal return' => TRUE,
    'commands' => array(),
  );
  $form_info = array(
    'path' => $this
      ->get_url('add-pane', $region, $type_name, $subtype_name, '%step'),
    'show cancel' => TRUE,
    'next callback' => 'panels_ajax_edit_pane_next',
    'finish callback' => 'panels_ajax_edit_pane_finish',
    'cancel callback' => 'panels_ajax_edit_pane_cancel',
  );
  $output = ctools_content_form('add', $form_info, $form_state, $content_type, $pane->subtype, $subtype, $pane->configuration, $step);

  // If $rc is FALSE, there was no actual form.
  if ($output === FALSE || !empty($form_state['complete'])) {
    $pane = $this->cache->new_pane;
    unset($this->cache->new_pane);

    // Add the pane to the display
    $this->display
      ->add_pane($pane, $region);
    panels_edit_cache_set($this->cache);

    // Tell the client to draw the pane
    $this
      ->command_add_pane($pane);

    // Dismiss the modal.
    $this->commands[] = ctools_modal_command_dismiss();
  }
  else {
    if (!empty($form_state['cancel'])) {

      // If cancelling, return to the activity.
      list($category_key, $category) = $this
        ->get_category($subtype);
      $this
        ->ajax_select_content($region, $category_key);
    }
    else {

      // This overwrites any previous commands.
      $this->commands = ctools_modal_form_render($form_state, $output);
    }
  }
}