function panels_common_ajax_context_item_edit in Panels 5.2
Ajax entry point to edit an item
1 call to panels_common_ajax_context_item_edit()
- panels_common_ajax in includes/
common.inc - Incoming menu function for ajax calls. This routes to the proper 'module' -- we really only need this because common.inc relies on panels.module for its menu hook, and this way the code stays together.
File
- includes/
common.inc, line 978 - Functions used by more than one panels client module.
Code
function panels_common_ajax_context_item_edit($module, $type, $panel_name) {
$object = panels_common_cache_get("panel_object:{$module}", $panel_name);
if (!$object) {
panels_ajax_render();
}
// Figure out which context we're adding
if (isset($_POST['position'])) {
$position = $_POST['position'];
}
if (!isset($_POST['form_id'])) {
// Unset $_POST so fapi doesn't get confused and try to process this
// as a form.
unset($_POST);
}
// Create a reference to the place our context lives.
$keyword = $type . 's';
$ref =& $object->{$keyword};
$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();
}
$type_info = panels_common_context_info($type);
$title = t('Edit @type "@context"', array(
'@type' => $type_info['singular title'],
'@context' => $info['title'],
));
$contexts = panels_context_load_contexts($object);
// Remove this context, because we can't really allow circular contexts.
// TODO: FIX THIS!!!
unset($contexts[panels_context_context_id($ref[$position])]);
$form_id = 'panels_common_edit_' . $type . '_form';
$form = drupal_retrieve_form($form_id, $object, $info, $position, $contexts);
if ($_POST && $_POST['form_id'] == $form_id) {
// TODO: Make sure the form does this.
$form['#redirect'] = FALSE;
}
$retval = drupal_process_form($form_id, $form);
if ($retval) {
$output = new stdClass();
// successful submit
// Save changes
$ref[$position] = $retval;
panels_common_cache_set("panel_object:{$module}", $panel_name, $object);
$output->type = $output->output = 'dismiss';
// Build a chunk of the form to merge into the displayed form
$arg_form[$type] = array(
'#tree' => TRUE,
);
panels_common_add_item_to_form($type, $arg_form[$type], $position, $retval);
$arg_form = form_builder($form_id, $arg_form);
$output->replace = theme('panels_common_context_item_row', $type, $arg_form[$type], $position, $position, FALSE);
$output->replace_id = '#' . $type . '-row-' . $position;
panels_ajax_render($output);
}
else {
$output = theme('status_messages');
$output .= drupal_render_form($form_id, $form);
panels_ajax_render($output, $title, url($_GET['q'], NULL, NULL, TRUE));
}
}