You are here

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

Same name and namespace in other branches
  1. 8 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 581

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;
}