You are here

function features_get_info in Features 7

Same name and namespace in other branches
  1. 6 features.module \features_get_info()
  2. 7.2 features.module \features_get_info()

Helper for retrieving info from system table.

6 calls to features_get_info()
features_admin_form in ./features.admin.inc
Form constructor for the features configuration form.
features_export_form_validate_field in ./features.admin.inc
Render API callback: Validates a project field.
features_get_features in ./features.module
Wrapper around features_get_info() that returns an array of module info objects that are features.
features_get_modules in ./features.module
Return a module 'object' including .info information.
template_preprocess_features_admin_components in theme/theme.inc
Display feature component info

... See full list

File

./features.module, line 592
Module file for the features module, which enables the capture and management of features in Drupal. A feature is a collection of Drupal entities which taken together statisfy a certain use-case.

Code

function features_get_info($type = 'module', $name = NULL, $reset = FALSE) {
  static $cache;
  if (!isset($cache)) {
    $cache = cache_get('features_module_info');
  }
  if (empty($cache) || $reset) {
    $data = array(
      'feature' => array(),
      'module' => array(),
    );
    $ignored = variable_get('features_ignored_orphans', array());
    $files = system_rebuild_module_data();

    // Filter out intentionally hidden features.
    module_load_include('inc', 'features', 'features.admin');
    $files = array_filter($files, 'features_filter_hidden');
    foreach ($files as $row) {

      // If module is no longer enabled, remove it from the ignored orphans list.
      if (in_array($row->name, $ignored, TRUE) && !$row->status) {
        $key = array_search($row->name, $ignored, TRUE);
        unset($ignored[$key]);
      }
      if (!empty($row->info['features'])) {

        // Fix css/js paths
        if (!empty($row->info['stylesheets'])) {
          foreach ($row->info['stylesheets'] as $media => $css) {
            $row->info['stylesheets'][$media] = array_keys($css);
          }
        }
        if (!empty($row->info['scripts'])) {
          $row->info['scripts'] = array_keys($row->info['scripts']);
        }
        $data['feature'][$row->name] = $row;
      }
      $data['module'][$row->name] = $row;
    }

    // Sort features according to dependencies.
    // @see install_profile_modules()
    $required = array();
    $non_required = array();
    $modules = array_keys($data['feature']);
    foreach ($modules as $module) {
      if ($files[$module]->requires) {
        $modules = array_merge($modules, array_keys($files[$module]->requires));
      }
    }
    $modules = array_unique($modules);
    foreach ($modules as $module) {
      if (!empty($files[$module]->info['features'])) {
        if (!empty($files[$module]->info['required'])) {
          $required[$module] = $files[$module]->sort;
        }
        else {
          $non_required[$module] = $files[$module]->sort;
        }
      }
    }
    arsort($required);
    arsort($non_required);
    $sorted = array();
    foreach ($required + $non_required as $module => $weight) {
      $sorted[$module] = $data['feature'][$module];
    }
    $data['feature'] = $sorted;
    variable_set('features_ignored_orphans', $ignored);
    cache_set("features_module_info", $data);
    $cache = new stdClass();
    $cache->data = $data;
  }
  if (!empty($name)) {
    return !empty($cache->data[$type][$name]) ? clone $cache->data[$type][$name] : array();
  }
  return !empty($cache->data[$type]) ? $cache->data[$type] : array();
}