You are here

function asaf_drupal_goto_alter in Asaf (ajax submit for any form) 7

Same name and namespace in other branches
  1. 8 asaf.module \asaf_drupal_goto_alter()

File

./asaf.module, line 67

Code

function asaf_drupal_goto_alter(&$path, &$options, &$http_response_code) {

  // Checking is asaf enabled
  if (asaf_is_asaf()) {

    // Trying to find actual $form and $form_state from stacktrace
    // TODO: This code a little bit smells, and should be refactored (if it's possible)
    list($form, $form_state) = _asaf_get_form_details_from_stacktrace();
    if (is_array($form) && is_array($form_state) && isset($form_state['triggering_element']['#asaf_control'])) {
      $form_state['redirect'] = array(
        $path,
        $options,
      );
      $page_callback_result = asaf_ajax_callback($form, $form_state);

      // Emulate correct response
      $router_item = menu_get_item(request_path());
      $default_delivery_callback = isset($router_item) && $router_item ? $router_item['delivery_callback'] : NULL;
      drupal_deliver_page($page_callback_result, $default_delivery_callback);
      exit;
    }
  }
}