You are here

function features_get_default in Features 6

Same name and namespace in other branches
  1. 7.2 features.export.inc \features_get_default()
  2. 7 features.export.inc \features_get_default()

Get defaults for a given module/component pair.

20 calls to features_get_default()
content_features_fields_default in includes/features.content.inc
Helper function: retrieve default fields by node type.
content_features_rebuild in includes/features.content.inc
Implementation of hook_features_rebuild(). Rebuilds CCK field definitions from code defaults.
context_features_revert in includes/features.context.inc
Implementation of hook_features_revert().
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.

... See full list

File

./features.export.inc, line 616

Code

function features_get_default($component, $module_name = NULL, $alter = TRUE, $reset = FALSE) {
  static $cache = array();
  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][$m]) || $reset) {

      // Special handling for dependencies component.
      if ($component === 'dependencies') {
        $module = features_get_features($m);
        $cache[$component][$m] = isset($module->info['dependencies']) ? $module->info['dependencies'] : array();
        unset($module);
      }
      else {
        if ($default_hook && function_exists("{$m}_{$default_hook}")) {
          $results = call_user_func("{$m}_{$default_hook}");
          if (!empty($results) && is_array($results)) {
            $cache[$component][$m] = $results;
            if ($alter) {
              drupal_alter($default_hook, $cache[$component][$m]);
            }
          }
          else {
            $cache[$component][$m] = FALSE;
          }
        }
        else {
          $cache[$component][$m] = FALSE;
        }
      }
    }
  }

  // A specific module was specified. Retrieve only its components.
  if (isset($module_name)) {
    return isset($cache[$component][$module_name]) ? $cache[$component][$module_name] : FALSE;
  }

  // No module was specified. Retrieve all components.
  $all_defaults = array();
  if (isset($cache[$component])) {
    foreach (array_filter($cache[$component]) as $module_components) {
      $all_defaults = array_merge($all_defaults, $module_components);
    }
  }
  return $all_defaults;
}