You are here

function module_builder_js in Module Builder 6

The JavaScript callback.

Uses magic too complex to be explained here.

1 string reference to 'module_builder_js'
module_builder_menu in ./module_builder.module
Implementation of hook_menu().

File

./module_builder.api.inc, line 123
API functions for the module_builder module

Code

function module_builder_js($param = '') {
  include_once drupal_get_path('module', 'module_builder') . '/module_builder.components.inc';
  $form_state = array(
    'storage' => NULL,
    'submitted' => FALSE,
  );
  $form_build_id = $_POST['form_build_id'];
  $form = form_get_cache($form_build_id, $form_state);

  // #parameters has $form_id, $form_state and then whatever was passed to
  // drupal_get_form.
  $args = $form['#parameters'];
  $form_id = array_shift($args);
  $form['#post'] = $_POST;
  $form['#redirect'] = FALSE;

  // This will set up $form_state['clicked_button'] and
  // $form_state['storage']['mlid'].
  drupal_process_form($form_id, $form, $form_state);

  // Recreate and re-cache the form.
  $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);

  // Pick up the parents of the pressed button.
  $array_parents = $form_state['clicked_button']['#array_parents'];

  // The last parent is the button itself, we need the wrapper instead.
  array_pop($array_parents);
  while ($array_parents) {
    $parent = array_shift($array_parents);
    $form = $form[$parent];
  }

  // Remove the button.
  unset($form['parent_submit']);

  // Render messages and selects.
  $output = theme('status_messages') . drupal_render($form);
  drupal_json(array(
    'status' => TRUE,
    'data' => $output,
  ));
}