You are here

function ctools_context_ajax_item_delete in Chaos Tool Suite (ctools) 6

Same name and namespace in other branches
  1. 7 includes/context-admin.inc \ctools_context_ajax_item_delete()

Ajax entry point to edit an item

1 string reference to 'ctools_context_ajax_item_delete'
ctools_context_menu in includes/context.menu.inc
@file Contains menu item registration for the context tool.

File

includes/context-admin.inc, line 935
includes/common-context.inc Provide API for adding contexts for modules that embed displays.

Code

function ctools_context_ajax_item_delete($module = NULL, $type = NULL, $object_name = NULL, $position = NULL) {
  ctools_include('ajax');
  ctools_include('context');
  ctools_include('object-cache');
  if (!isset($position)) {
    return ctools_ajax_render_error();
  }

  // Load stored object from cache.
  if (!($object = ctools_context_cache_get($module, $object_name))) {
    ctools_ajax_render_error(t('Invalid object name.'));
  }
  $type_info = ctools_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']};
  if (!array_key_exists($position, $ref)) {
    ctools_ajax_render_error(t('Unable to delete missing item!'));
  }
  unset($ref[$position]);
  ctools_context_cache_set($module, $object_name, $object);
  $output = array();
  $output[] = ctools_ajax_command_replace('#' . $type . '-row-' . $position, '');
  $output[] = ctools_ajax_command_restripe("#{$type}-table");
  ctools_ajax_render($output);
}