function panels_renderer_editor::ajax_add_pane in Panels 7.3
Same name and namespace in other branches
- 6.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 684 - 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);
// Determine if we are adding a different pane than previously cached. This
// is used to load the different pane into cache so that multistep forms
// have the correct context instead of a previously cached version that
// does not match the pane currently being added.
$is_different_pane = FALSE;
if (isset($this->cache) && isset($this->cache->new_pane)) {
$diff_type = $type_name != $this->cache->new_pane->type;
$diff_subtype = $subtype_name != $this->cache->new_pane->subtype;
$is_different_pane = $diff_type || $diff_subtype;
}
if (!isset($step) || !isset($this->cache->new_pane) || $is_different_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,
'display 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'])) {
// References get blown away with AJAX caching. This will fix that.
$pane = $form_state['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();
}
elseif (!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);
}
}