You are here

function panels_ajax_cache_method in Panels 6.2

Entry point for AJAX modal: configure pane cache method

Related topics

1 string reference to 'panels_ajax_cache_method'
panels_menu in ./panels.module
Implementation of hook_menu

File

includes/display-edit.inc, line 716

Code

function panels_ajax_cache_method($did = NULL, $pid = NULL) {
  panels_load_include('plugins');
  panels_load_include('ajax');
  if (!is_numeric($did) && $did != 'new' || !($cache = panels_cache_get('display', $did))) {
    panels_ajax_render(t('Invalid display id.'));
  }

  // This lets us choose whether we're doing the display's cache or
  // a pane's.
  if ($pid == 'display') {
    $conf =& $cache->display->cache;
    $title = t('Cache method for this display');
  }
  else {
    if (!empty($cache->display->content[$pid])) {
      $pane = $cache->display->content[$pid];
      $subtypes = panels_ct_get_types($pane->type);
      $conf =& $cache->display->content[$pid]->configuration;
      $title = t('Cache method for !subtype_title', array(
        '!subtype_title' => $subtypes[$pane->subtype]['title'],
      ));
    }
    else {
      panels_ajax_render(t('Invalid pane id.'));
    }
  }
  $form_state = array(
    'display' => &$cache->display,
    'conf' => &$conf,
    'title' => $title,
    'ajax' => TRUE,
  );
  $output = panels_ajax_form_wrapper('panels_edit_cache_method_form', $form_state);
  if (empty($output)) {

    // Preserve this; this way we don't actually change the method until they
    // have saved the form.
    $function = panels_plugin_get_function('cache', $form_state['method'], 'settings form');
    if (!$function) {

      // This cache method has no settings form, so just save and dismiss.
      $conf['method'] = $form_state['method'];
      $conf['settings'] = array();
      panels_cache_set('display', $did, $cache);
      $output = new stdClass();
      $output->type = 'dismiss';
      $output->output = 'dummy';
      if ($pid != 'display') {
        $output->id = "panel-pane-{$pid}";
      }
    }
    else {
      $cache->method = $form_state['method'];
      panels_cache_set('display', $did, $cache);

      // send them to next form.
      return panels_ajax_cache_settings($cache, $pid);
    }
  }
  panels_ajax_render($output);
}