You are here

function features_include_defaults in Features 7.2

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

Includes PHP files that contain (generated) default hook implementations.

The file to include for each feature module for a given component can be specified in the component info in hook_features_api().

Parameters

string[]|string|null $components: (optional) A list of component names, or one component name, or NULL. If provided, only the files for the specified components are included.

bool $reset: (optional) If TRUE, the operation will run again even if it has already run during the same request. This is useful e.g. when new modules were enabled.

3 calls to features_include_defaults()
features_get_default in ./features.export.inc
Get defaults for a given module/component pair.
features_get_default_map in ./features.export.inc
Gets a map of components to their providing modules.
features_modules_enabled in ./features.module
Implements hook_modules_enabled().

File

./features.module, line 498
Main *.module file for the 'features' module.

Code

function features_include_defaults($components = NULL, $reset = FALSE) {
  static $include_components;

  // Build an array of components that require inclusion:
  // Views, CTools components and those using FEATURES_DEFAULTS_INCLUDED.
  if (!isset($include_components) || $reset) {
    $include_components = features_get_components();
    foreach ($include_components as $component => $info) {
      if (!isset($info['api']) && (!isset($info['default_file']) || $info['default_file'] !== FEATURES_DEFAULTS_INCLUDED)) {
        unset($include_components[$component]);
      }
    }
  }

  // If components are specified, only include for the specified components.
  if (isset($components)) {
    $components = is_array($components) ? $components : array(
      $components,
    );
  }
  else {
    $components = array_keys($include_components);
  }
  foreach ($components as $component) {
    if (isset($include_components[$component])) {
      $info = $include_components[$component];

      // Inclusion of ctools components.
      if (isset($info['api'], $info['module'], $info['current_version'])) {
        ctools_include('plugins');
        ctools_plugin_api_include($info['module'], $info['api'], $info['current_version'], $info['current_version']);
      }
      else {
        $features = isset($features) ? $features : features_get_features(NULL, $reset);
        foreach ($features as $feature) {
          $filename = isset($info['default_file']) && $info['default_file'] == FEATURES_DEFAULTS_CUSTOM ? $info['default_filename'] : "features.{$component}";
          if (module_exists($feature->name) && isset($feature->info['features'][$component])) {
            module_load_include('inc', $feature->name, "{$feature->name}.{$filename}");
          }
        }
      }
    }
  }
}