function features_get_default in Features 7
Same name and namespace in other branches
- 6 features.export.inc \features_get_default()
- 7.2 features.export.inc \features_get_default()
Get defaults for a given module/component pair.
18 calls to features_get_default()
- ctools_component_features_revert in includes/
features.ctools.inc - Master implementation of hook_features_revert() for all ctools components.
- features_detect_overrides in ./
features.export.inc - Detect differences between DB and code components of a feature.
- features_get_default_map in ./
features.export.inc - Get a map of components to their providing modules.
- features_get_signature in ./
features.export.inc - Wrapper around features_get_[storage] to return an md5hash of a normalized defaults/normal object array. Can be used to compare normal/default states of a module's component.
- field_features_rebuild in includes/
features.field.inc - Implements of hook_features_rebuild(). Rebuilds fields from code defaults.
File
- ./
features.export.inc, line 637
Code
function features_get_default($component, $module_name = NULL, $alter = TRUE, $reset = FALSE) {
static $cache = array();
$alter = !empty($alter);
// ensure $alter is a true/false boolean
features_include();
features_include_defaults($component);
$default_hook = features_get_default_hooks($component);
$components = features_get_components();
// Collect defaults for all modules if no module name was specified.
if (isset($module_name)) {
$modules = array(
$module_name,
);
}
else {
if ($component === 'dependencies') {
$modules = array_keys(features_get_features());
}
else {
$modules = array();
foreach (features_get_component_map($component) as $component_modules) {
$modules = array_merge($modules, $component_modules);
}
$modules = array_unique($modules);
}
}
// Collect and cache information for each specified module.
foreach ($modules as $m) {
if (!isset($cache[$component][$alter][$m]) || $reset) {
// Special handling for dependencies component.
if ($component === 'dependencies') {
$module = features_get_features($m);
$cache[$component][$alter][$m] = isset($module->info['dependencies']) ? $module->info['dependencies'] : array();
unset($module);
}
else {
if ($default_hook && module_hook($m, $default_hook)) {
$cache[$component][$alter][$m] = call_user_func("{$m}_{$default_hook}");
if (is_array($cache[$component][$alter][$m])) {
$alter_type = features_get_components('alter_type', $component);
if ($alter && (!isset($alter_type) || $alter_type == FEATURES_ALTER_TYPE_NORMAL)) {
if ($alter_hook = features_get_default_alter_hook($component)) {
drupal_alter($alter_hook, $cache[$component][$alter][$m]);
}
}
}
else {
$cache[$component][$alter][$m] = FALSE;
}
}
else {
$cache[$component][$alter][$m] = FALSE;
}
}
}
}
// A specific module was specified. Retrieve only its components.
if (isset($module_name)) {
return isset($cache[$component][$alter][$module_name]) ? $cache[$component][$alter][$module_name] : FALSE;
}
// No module was specified. Retrieve all components.
$all_defaults = array();
if (isset($cache[$component][$alter])) {
foreach (array_filter($cache[$component][$alter]) as $module_components) {
$all_defaults = array_merge($all_defaults, $module_components);
}
}
return $all_defaults;
}