You are here

function date_repeat_get_exception_form_ajax in Date 6.2

Ajax callback to get the exceptions form. This is needed to implement the "Add another" button for the date repeat exceptions.

Parameters

$type - 'exceptions' or 'additions'.:

$field_name - The name of the date field.:

1 string reference to 'date_repeat_get_exception_form_ajax'
date_repeat_menu in date_repeat/date_repeat.module
Implementation of hook_menu.

File

date_repeat/date_repeat_form.inc, line 266
Code to add a date repeat selection form to a date field and create an iCal RRULE from the chosen selections.

Code

function date_repeat_get_exception_form_ajax($type, $field_name) {

  // Get the cached form.
  $form_state = array(
    'storage' => NULL,
    'submitted' => FALSE,
  );
  if (!($form = form_get_cache($_POST['form_build_id'], $form_state))) {
    drupal_json(array(
      'status' => FALSE,
      'data' => '',
    ));
    exit;
  }

  // Set the form state values.
  $form_state = array_merge($form_state, array(
    'values' => $_POST,
  ));

  // Set the new form rrule value.
  $form[$field_name]['rrule']['#value'] = $form_state['values'][$field_name]['rrule'];

  // Cache the new form state.
  form_set_cache($_POST['form_build_id'], $form, $form_state);

  // Rebuild the form.
  $form_state = array();
  $form['#post'] = array();
  $form = form_builder($form['form_id']['#value'], $form, $form_state);

  // Force a rebuild of the Drupal.settings javascript object.
  //   - Borrowed from content.node_form.inc, content_add_more_js function
  $javascript = drupal_add_js(NULL, NULL);
  $output_js = isset($javascript['setting']) ? '<script type="text/javascript">jQuery.extend(Drupal.settings, ' . drupal_to_js(call_user_func_array('array_merge_recursive', $javascript['setting'])) . ');</script>' : '';

  // Create our output.
  $output = drupal_render($form[$field_name]['rrule'][$type]) . $output_js;

  // Set the new exceptions form.
  drupal_json(array(
    'status' => TRUE,
    'data' => $output,
  ));
  exit;
}