You are here

function delta_ahah in Delta 6

Same name and namespace in other branches
  1. 7 delta.module \delta_ahah()
1 string reference to 'delta_ahah'
delta_menu in ./delta.module
Implementation of hook_menu().

File

./delta.module, line 800
The Delta Theme API is an advanced manipulation of the Theme Settings API to allow for customization/configuration of theme settings based on node types, context, or groups of paths.

Code

function delta_ahah() {

  // this part is used to set up $form_state.
  // In Drupal 7, these next 11 lines will be put in a core utility function.
  // Just remember you'll need them in D6 when you do AHAH!
  $form_state = array(
    'storage' => NULL,
    'submitted' => FALSE,
  );

  //$form_state = array('storage' => NULL, 'rebuild' => TRUE);
  $form_build_id = $_POST['form_build_id'];
  $form = form_get_cache($form_build_id, $form_state);
  $args = $form['#parameters'];
  $form_id = array_shift($args);
  $form['#post'] = $_POST;
  $form['#redirect'] = FALSE;
  $form['#programmed'] = FALSE;
  $form_state['post'] = $_POST;
  drupal_process_form($form_id, $form, $form_state);
  $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);

  // From here on, we start our own code.
  // We just get the element of $form that needs to be refreshed, and just resubmit that
  // part through the json call. In this case we want to replace the 'kind' <div> wrapper and it's
  // containing select box
  $changed_elements = $form['delta_override']['tst'];

  //unset($changed_elements['#prefix'], $changed_elements['suffix']); // we'll unset the div to make sure it won't be repeated!

  // the actual JSON call
  $javascript = drupal_add_js(NULL, NULL, 'header');
  drupal_json(array(
    'status' => TRUE,
    'data' => theme('status_messages') . drupal_render($changed_elements),
    // rebuild just the part that needs to be changed
    'settings' => call_user_func_array('array_merge_recursive', $javascript['setting']),
  ));
}