function panels_ajax_context_item_edit in Panels 6.2
Ajax entry point to edit an item
1 string reference to 'panels_ajax_context_item_edit'
- panels_menu in ./
panels.module - Implementation of hook_menu
File
- includes/
common-context.inc, line 485 - includes/common-context.inc Provide API for adding contexts for modules that embed displays.
Code
function panels_ajax_context_item_edit($module = NULL, $type = NULL, $panel_name = NULL, $position = NULL) {
panels_load_include('plugins');
panels_load_include('ajax');
if (!isset($position)) {
return panels_ajax_render();
}
// Load stored object from cache.
if (!($object = panels_cache_get("panel_object:{$module}", $panel_name))) {
panels_ajax_render(t('Invalid panel name.'));
}
$type_info = panels_common_context_info($type);
// Create a reference to the place our context lives. Since this is fairly
// generic, this is the easiest way to get right to the place of the
// object without knowing precisely what data we're poking at.
$ref =& $object->{$type_info['key']};
$name = $ref[$position]['name'];
if (empty($name)) {
panels_ajax_render();
}
// load the context
$info = panels_common_context_data($type, $name);
if (empty($info)) {
panels_ajax_render(t('Invalid context type'));
}
$base_contexts = isset($object->base_contexts) ? $object->base_contexts : array();
$contexts = panels_context_load_contexts($object, TRUE, $base_contexts);
// Remove this context, because we can't really allow circular contexts.
unset($contexts[panels_context_id($ref[$position])]);
$form_state = array(
'object' => &$object,
'module' => $module,
'type' => $type,
'name' => $name,
'ajax' => TRUE,
'info' => $info,
'position' => $position,
'contexts' => $contexts,
'ref' => &$ref,
'title' => t('Edit @type "@context"', array(
'@type' => $type_info['singular title'],
'@context' => $info['title'],
)),
);
$output = panels_ajax_form_wrapper($type_info['form id'], $form_state);
if (empty($output)) {
// successful submit
panels_cache_set("panel_object:{$module}", $panel_name, $object);
$output = new stdClass();
$output->type = $output->output = 'dismiss';
$arg_form = array(
'#post' => array(),
'#programmed' => FALSE,
'#tree' => FALSE,
);
// Build a chunk of the form to merge into the displayed form
$arg_form[$type] = array(
'#tree' => TRUE,
);
$arg_form[$type][$position] = array(
'#tree' => TRUE,
);
panels_common_add_item_to_form($module, $type, $panel_name, $arg_form[$type][$position], $position, $ref[$position]);
$arg_form = form_builder($type_info['form id'], $arg_form, $arg_form_state);
$output->replace = array(
'#' . $type . '-row-' . $position => theme('panels_common_context_item_row', $type, $arg_form[$type][$position], $position, $position),
);
}
panels_ajax_render($output);
}