function features_get_info in Features 7.2
Same name and namespace in other branches
- 6 features.module \features_get_info()
- 7 features.module \features_get_info()
Retrieves module info from the system table.
Parameters
string $type: (optional) One of 'module' or 'feature'. If 'module', all modules are returned. If 'feature', only those modules are returned that act as features.
string|null $name: (optional) Name of a (feature or not) module. If the module is not a feature, and $type is 'feature', FALSE will be returned instead.
bool $reset: (optional) If TRUE, the cache will be cleared before fetching.
Return value
\stdClass[]|\stdClass|false If $name is NULL or empty: List of modules according to $type. Format: $[$module] = $module_info_object If $name is not NULL or empty: Module info object, if it matches $type. FALSE, if the module does not exist, or if $type is 'feature' and the module is not a feature. If $type is something other than 'module' or 'feature': FALSE, no matter the other parameters.
See also
6 calls to features_get_info()
- features_export_form_module_name_exists in ./
features.admin.inc - Machine name existence callback for the module name.
- features_get_features in ./
features.module - Gets a list 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.
- _ctools_features_get_info in includes/
features.ctools.inc - Helper function to return various ctools information for components.
File
- ./
features.module, line 827 - Main *.module file for the 'features' module.
Code
function features_get_info($type = 'module', $name = NULL, $reset = FALSE) {
static $cache;
if (!isset($cache)) {
$cache = cache_get('features_module_info', 'cache_features');
}
if (empty($cache) || $reset) {
$data = array(
'feature' => array(),
'module' => array(),
);
$ignored = variable_get('features_ignored_orphans', array());
$files = system_rebuild_module_data();
foreach ($files as $row) {
// Remove modification timestamp, added in Drupal 7.33.
if (isset($row->info['mtime'])) {
unset($row->info['mtime']);
}
// Avoid false-reported feature overrides for php = 5.2.4 line in .info
// file.
if (isset($row->info['php'])) {
unset($row->info['php']);
}
// 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']);
}
// Rework the features array, to change the vocabulary permission
// features.
foreach ($row->info['features'] as $component => $features) {
if ($component == 'user_permission') {
foreach ($features as $key => $feature) {
// Export vocabulary permissions using the machine name, instead
// of vocabulary id.
_user_features_change_term_permission($feature);
$row->info['features'][$component][$key] = $feature;
}
}
}
$data['feature'][$row->name] = $row;
$data['feature'][$row->name]->components = array_keys($row->info['features']);
if (!empty($row->info['dependencies'])) {
$data['feature'][$row->name]->components[] = 'dependencies';
}
}
$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_features');
$cache = new stdClass();
$cache->data = $data;
}
if (!empty($name)) {
return !empty($cache->data[$type][$name]) ? clone $cache->data[$type][$name] : FALSE;
}
return !empty($cache->data[$type]) ? $cache->data[$type] : FALSE;
}