You are here

function features_get_default in Features 7.2

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

Get defaults for a given module/component pair.

Parameters

string $component: A component name, e.g. 'field_instance'.

string|null $module_name: (optional) If specified, only return defaults for this module.

bool $alter: (optional) If TRUE, the defaults will be passed through an alter hook.

bool $reset: If TRUE, the static cache will be reset.

Return value

array[]|object[]|mixed[]|false Format: $[$name] = $item_export_data Object data as defined in code. For most components, this is the data returned from the component hook implementation(s). For some components these are actual objects, for others they are arrays or perhaps just strings.

21 calls to features_get_default()
contact_categories_features_rebuild in includes/features.contact.inc
Implements hook_features_rebuild().
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
Gets a map of components to their providing modules.
features_get_signature in ./features.export.inc
Gets an md5 signature for a the state of an object in code or database.

... See full list

File

./features.export.inc, line 1175
Contains functions that export configuration into feature modules.

Code

function features_get_default($component, $module_name = NULL, $alter = TRUE, $reset = FALSE) {
  $cache =& drupal_static(__FUNCTION__, array());

  // Ensure $alter is a true/false boolean.
  $alter = !empty($alter);
  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;
}