You are here

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

Same name and namespace in other branches
  1. 7 asaf.module \_asaf_get_form_parent_module()
1 call to _asaf_get_form_parent_module()
asaf_get_form_stuff in ./asaf.module

File

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

Code

function _asaf_get_form_parent_module($form_id, $form_state) {
  $parent = array();

  // If in the same folder we well find a few modules we will load all of them
  $constructor = _asaf_get_form_constructor($form_id, $form_state);
  if (function_exists($constructor) && class_exists('ReflectionFunction')) {
    $reflection = new ReflectionFunction($constructor);
    $file = $reflection
      ->getFileName();
    $directory = dirname($file);
    $pattern = '/.module$/';
    $i = 20;

    // just in case :)
    while (empty($parents) && $directory != DRUPAL_ROOT && $i) {
      $matches = array_keys(file_scan_directory($directory, $pattern, array(
        'recurse' => FALSE,
      )));
      if (is_array($matches)) {
        foreach ($matches as $module) {
          $info = pathinfo($module);
          $parent[] = $info['filename'];
        }
      }
      $directory = dirname($directory);
      $i--;
    }
  }
  return !empty($parent) ? $parent : FALSE;
}