You are here

function stringoverrides_js in String Overrides 6

Menu callback for the String Overrides module to display a new string override

1 string reference to 'stringoverrides_js'
stringoverrides_menu in ./stringoverrides.module
Implementation of hook_menu()

File

./stringoverrides.admin.inc, line 180
Admin page callbacks for the String Overrides module.

Code

function stringoverrides_js() {
  $delta = count($_POST['string']);

  // Build our new form element.
  $form_element = stringoverrides_textbox_combo($delta);
  drupal_alter('form', $form_element, array(), 'stringoverrides_js');

  // Build the new form.
  $form_state = array(
    'submitted' => FALSE,
  );
  $form_build_id = $_POST['form_build_id'];

  // Add the new element to the stored form. Without adding the element to the
  // form, Drupal is not aware of this new elements existence and will not
  // process it. We retreive the cached form, add the element, and resave.
  $form = form_get_cache($form_build_id, $form_state);
  $form['string'][$delta] = $form_element;
  form_set_cache($form_build_id, $form, $form_state);
  $form += array(
    '#post' => $_POST,
    '#programmed' => FALSE,
  );

  // Rebuild the form.
  $form = form_builder('stringoverrides_admin', $form, $form_state);

  // Render the new output.
  $string_form = $form['string'];
  $string_form[$delta]['enabled']['#value'] = TRUE;
  $string_form[$delta]['#attributes']['class'] = empty($string_form[$delta]['#attributes']['class']) ? 'ahah-new-content' : $string_form[$delta]['#attributes']['class'] . ' ahah-new-content';
  $output = theme('status_messages') . drupal_render($string_form);
  drupal_json(array(
    'status' => TRUE,
    'data' => $output,
  ));
}