You are here

function ctools_access_ajax_edit in Chaos Tool Suite (ctools) 7

Same name and namespace in other branches
  1. 6 includes/context-access-admin.inc \ctools_access_ajax_edit()

AJAX callback to edit an access test in the list.

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

File

includes/context-access-admin.inc, line 330
Contains administrative screens for the access control plugins.

Code

function ctools_access_ajax_edit($fragment = NULL, $id = NULL) {
  ctools_include('ajax');
  ctools_include('modal');
  ctools_include('context');
  if (empty($fragment) || !isset($id)) {
    ctools_ajax_render_error();
  }

  // Separate the fragment into 'module' and 'argument'.
  if (strpos($fragment, '-') === FALSE) {
    $module = $fragment;
    $argument = NULL;
  }
  else {
    list($module, $argument) = explode('-', $fragment, 2);
  }
  $function = $module . '_ctools_access_get';
  if (!function_exists($function)) {
    ctools_ajax_render_error(t('Missing callback hooks.'));
  }
  list($access, $contexts) = $function($argument);
  if (empty($access['plugins'][$id])) {
    ctools_ajax_render_error();
  }

  // Make sure we have the logged in user context.
  if (!isset($contexts['logged-in-user'])) {
    $contexts['logged-in-user'] = ctools_access_get_loggedin_context();
  }
  $plugin = ctools_get_access_plugin($access['plugins'][$id]['name']);
  $form_state = array(
    'plugin' => $plugin,
    'id' => $id,
    'test' => &$access['plugins'][$id],
    'access' => &$access,
    'contexts' => $contexts,
    'title' => t('Edit criteria'),
    'ajax' => TRUE,
    'modal' => TRUE,
    'modal return' => TRUE,
  );
  $output = ctools_modal_form_wrapper('ctools_access_ajax_edit_item', $form_state);
  $access = $form_state['access'];
  $access['plugins'][$id] = $form_state['test'];
  if (!isset($output[0])) {
    $function = $module . '_ctools_access_set';
    if (function_exists($function)) {
      $function($argument, $access);
    }
    $table = ctools_access_admin_render_table($access, $fragment, $contexts);
    $output = array();
    $output[] = ajax_command_replace('table#ctools-access-table', $table);
    $output[] = ctools_modal_command_dismiss();
  }
  print ajax_render($output);
}