You are here

function fetch_module_weights in Util 6.3

Same name and namespace in other branches
  1. 6.2 module_weights.module \fetch_module_weights()

Helper function to fetch and cache module weights.

3 calls to fetch_module_weights()
module_weights_form_alter in ./module_weights.module
Implements hook_form_alter().
module_weights_system_module_submit in ./module_weights.module
Implements form_submit().
module_weights_system_module_validate in ./module_weights.module
Implements form_validate().

File

./module_weights.module, line 61
Allows module weights to be viewed and edited.

Code

function fetch_module_weights($name = NULL) {
  static $module_weights = array();
  if (empty($module_weights)) {
    $query = "SELECT filename, name, type, owner, status, throttle, bootstrap, schema_version, weight FROM {system} WHERE type = 'module' ORDER BY name";
    $result = db_query($query);
    while ($row = db_fetch_object($result)) {

      // When a module is deleted, it remains in the system table.
      // If module has been deleted, omit it from the list.
      if (file_exists($row->filename)) {
        $module_weights[$row->name] = empty($row->weight) ? 0 : $row->weight;
      }
      else {

        // Do we want a warning?
        if (variable_get('module_weights_warning', 0)) {
          if ($row->status) {
            drupal_set_message(t('@name module file (@file) could not be found, but is still marked as "enabled!"', array(
              '@name' => $row->name,
              '@file' => $row->filename,
            )), 'warning');
          }
          else {
            drupal_set_message(t('@name module file (@file) could not be found.', array(
              '@name' => $row->name,
              '@file' => $row->filename,
            )));
          }
        }
      }
    }
  }
  if ($name === NULL) {
    return $module_weights;
  }
  elseif (isset($module_weights[$name])) {
    return $module_weights[$name];
  }
  else {
    return NULL;
  }
}