You are here

function ctools_context_ajax_item_delete in Chaos Tool Suite (ctools) 7

Same name and namespace in other branches
  1. 6 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 775
includes/common-context.inc Provide API for adding contexts for modules that embed displays.

Code

function ctools_context_ajax_item_delete($mechanism = NULL, $type = NULL, $cache_key = NULL, $position = NULL) {
  ctools_include('ajax');
  ctools_include('context');
  ctools_include('cache');
  if (!isset($position)) {
    return ctools_ajax_render_error();
  }

  // Load stored object from cache.
  if (!($object = ctools_cache_get($mechanism, $cache_key))) {
    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_cache_operation($mechanism, $cache_key, 'finalize', $object);
  $output = array();
  $output[] = ajax_command_replace('#' . $type . '-row-' . $position, '');
  $output[] = ajax_command_restripe("#{$type}-table");
  print ajax_render($output);
  exit;
}