You are here

function _asaf_get_form_details_from_stacktrace in Asaf (ajax submit for any form) 8

Same name and namespace in other branches
  1. 7 asaf.module \_asaf_get_form_details_from_stacktrace()
2 calls to _asaf_get_form_details_from_stacktrace()
asaf_batch_alter in ./asaf.module
asaf_drupal_goto_alter in ./asaf.module

File

./asaf.module, line 630
Main module file.

Code

function _asaf_get_form_details_from_stacktrace() {
  static $form;
  static $form_state;
  if (!$form || !$form_state) {
    $stacktrace = debug_backtrace();
    foreach ($stacktrace as $step) {
      $args = isset($step['args']) ? $step['args'] : FALSE;
      if (is_array($args)) {
        foreach ($args as $arg) {
          if (!$form && is_array($arg) && isset($arg['#type']) && $arg['#type'] == 'form') {
            $form = $arg;
          }
          if (!$form_state && is_array($arg) && isset($arg['build_info']) && is_array($arg['build_info'])) {
            $form_state = $arg;
          }
        }
        if ($form && $form_state) {
          break;
        }
      }
    }
  }
  return array(
    $form,
    $form_state,
  );
}