You are here

function bigmenu_slice_form_js in Big Menu 6

Same name and namespace in other branches
  1. 7 bigmenu.admin.inc \bigmenu_slice_form_js()

Return a submenu slice form in json format Menu callback, invoked by AJAX

Drupals form cache would not allow me to insert arbitrary fields into a form without letting the server know about it.

1 string reference to 'bigmenu_slice_form_js'
bigmenu_menu in ./bigmenu.module
Declare admin links and AJAX callbacks

File

./bigmenu.admin.inc, line 119
Administrative page callbacks for bigmenu module.

Code

function bigmenu_slice_form_js($menu, $menu_link, $form_id, $form_build_id) {
  $depth = 2;
  $form_state = array();
  $slice_form_id = 'bigmenu_slice_form';
  $output = drupal_get_form('bigmenu_slice_form', $menu, $menu_link, $depth);

  # Or maybe,

  # Need to do the things that drupal_get_form would do,

  # but retain the form_object for the next step also.

  # Maybe not?

  #  $slice_form = drupal_retrieve_form($slice_form_id, $form_state, $menu, $menu_link, $depth);

  #  drupal_prepare_form($slice_form_id, $slice_form, $form_state);

  #  drupal_process_form($slice_form_id, $slice_form, $form_state);

  #  $output = drupal_render_form($slice_form_id, $slice_form);

  // This returns data to the browser immediately.
  drupal_json(array(
    'status' => TRUE,
    'data' => $output,
  ));

  // After that we will do the slower job of updating the form cache.
  // Reload the bigmenu_overview_form, with the same args (the menu name) as before,
  // What are the following three lines doing? Search me.
  // I read the docs on drupal_rebuild_form() and took a guess.
  $form_state = array();
  $args = array(
    $form_state,
    $menu,
  );
  $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);

  // Just calling drupal_rebuild_form will also re-cache it with the new fields?
  // How does it know?

  # I thought I would have to:

  # Then insert the new fields into the cached overview form from the slice form.

  # $form += $slice_form;
  exit;
}