You are here

function site_disclaimer_js in Site Disclaimer 6

Same name and namespace in other branches
  1. 7 site_disclaimer.admin.inc \site_disclaimer_js()

Menu callback for AHAH addition.

1 string reference to 'site_disclaimer_js'
site_disclaimer_menu in ./site_disclaimer.module
Implementation of hook_menu().

File

./site_disclaimer.admin.inc, line 373
Administration settings for Site Disclaimer module.

Code

function site_disclaimer_js() {

  // D6 AHAH
  // Build the new form the way D6 AHAH helper works. This allows more D7-like code with all work done in form build function.
  $form_state = array(
    'storage' => NULL,
    'submitted' => FALSE,
  );
  $form_build_id = check_plain($_POST['form_build_id']);
  $form = form_get_cache($form_build_id, $form_state);
  $args = $form['#parameters'];
  $form_id = array_shift($args);
  $form_state['post'] = $form['#post'] = $_POST;
  $form['#programmed'] = $form['#redirect'] = FALSE;

  // some uploaded files mgmt here in D6 AHAH helper, not needed in our case
  $form_state['submitted'] = TRUE;

  // some examples don't have this line. it prevents a nasty _form_builder_ie_cleanup() from firing according to D6 AHAH helper, but will invoke submit handlers...
  $form_state['rebuild'] = TRUE;

  // this will prevent submit handlers from firing (D6 AHAH helper does not have this)
  if (!isset($_POST['op'])) {
    $form['#validate'] = NULL;
    $form['#submit'] = NULL;
    $form_state['submit_handlers'] = NULL;
    $form_state['validate_handlers'] = NULL;
    _site_disclaimer_disable_validation($form);
  }
  drupal_process_form($form_id, $form, $form_state);
  $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);

  // Get the JS settings so we can merge them. (this revives other JS-enabled controls, i.e autocomplete on node_title)
  $javascript = drupal_add_js(NULL, NULL, 'header');
  $settings = call_user_func_array('array_merge_recursive', $javascript['setting']);

  // Remove message inserted by system_settings_form() as we don't want to show it in AHAH updates.
  $pos = isset($_SESSION['messages']['error']) ? array_search(t('The settings have not been saved because of the errors.'), $_SESSION['messages']['error']) : FALSE;
  if ($pos !== FALSE) {
    unset($_SESSION['messages']['error'][$pos]);
  }

  // Render the new output.
  $output = theme('status_messages') . drupal_render($form['site_disclaimer_text']);
  drupal_json(array(
    'status' => TRUE,
    'data' => $output,
    'settings' => array(
      'ahah' => $settings['ahah'],
    ),
  ));
}