diff --git a/features.module b/features.module index ba5b9fe..4073cda 100644 --- a/features.module +++ b/features.module @@ -331,18 +331,37 @@ function features_modules_disabled($modules) { function features_modules_enabled($modules) { // Go through all modules and gather features that can be enabled. $items = array(); + + // Check if any of the enabled modules create new components. + $new_components = array_intersect(module_implements('features_api'), $modules); + + // Check if any of the natively supported modules have been enabled. + $new_modules = array_intersect(array('features', 'block', 'context', 'field', 'filter', 'image', 'locale', 'menu', 'node', 'taxonomy', 'user', 'views', 'ctools'), $modules); + + // Check if any of the enabled modules contain features. + $new_features = array(); + foreach ($modules as $module) { if ($feature = features_load_feature($module)) { $items[$module] = array_keys($feature->info['features']); + $new_features[$module] = array_keys($feature->info['features']); } } + // Clear components cache and load new include files if needed. + if (!empty($new_components) || !empty($new_modules) || !empty($new_features)) { + features_include(TRUE); + features_include_defaults(NULL, TRUE); + } + + // Enable the new features. + if (!empty($new_features)) { + features_include_defaults(NULL, TRUE); + _features_restore('enable', $new_features); + } + if (!empty($items)) { - // Need to include any new files. - // @todo Redo function so can take in list of modules to include. features_include_defaults(NULL, TRUE); - _features_restore('enable', $items); - // Rebuild the list of features includes. features_include(TRUE); // Reorders components to match hook order and removes non-existant. $all_components = array_keys(features_get_components()); @@ -519,6 +538,7 @@ function features_get_components($component = NULL, $key = NULL, $reset = FALSE) $components = $cache->data; } else { + module_implements('features_api', FALSE, $reset); $components = module_invoke_all('features_api'); drupal_alter('features_api', $components); cache_set('features_api', $components); diff --git a/includes/features.taxonomy.inc b/includes/features.taxonomy.inc index a7c85cd..9b20818 100644 --- a/includes/features.taxonomy.inc +++ b/includes/features.taxonomy.inc @@ -78,6 +78,13 @@ function taxonomy_features_export_render($module, $data) { } /** + * Implements hook_features_enable_feature(). + */ +function taxonomy_features_enable_feature($module) { + taxonomy_features_rebuild($module); +} + +/** * Implements hook_features_revert(). */ function taxonomy_features_revert($module) { @@ -85,6 +92,13 @@ function taxonomy_features_revert($module) { } /** + * Implements hook_features_enable_feature(). + */ +function taxonomy_features_enable_feature($module) { + taxonomy_features_rebuild($module); +} + +/** * Implements hook_features_rebuild(). * * Rebuilds Taxonomy vocabularies from code defaults. diff --git a/includes/features.user.inc b/includes/features.user.inc index 2805a77..3e35954 100644 --- a/includes/features.user.inc +++ b/includes/features.user.inc @@ -40,6 +40,26 @@ function user_permission_features_export($data, &$export, $module_name = '') { } } + // Include features that provide user roles as dependencies. + foreach (features_get_component_map('user_role') as $role_map) { + foreach ($role_map as $feature) { + // Do not allow a module to depend on itself. + if ($feature != $module_name) { + $export['dependencies'][$feature] = $feature; + } + } + } + + // Include features that provide user roles as dependencies. + foreach (features_get_component_map('user_role') as $role_map) { + foreach ($role_map as $feature) { + // Do not allow a module to depend on itself. + if ($feature != $module_name) { + $export['dependencies'][$feature] = $feature; + } + } + } + return array(); } @@ -120,6 +140,26 @@ function user_permission_features_revert($module) { } /** + * Implements hook_features_enable_feature(). + */ +function user_permission_features_enable_feature($module) { + // If one feature contains both user roles and permissions, make sure the + // roles are reverted first so the permissions can be applied on them. + user_role_features_rebuild($module); + user_permission_features_rebuild($module); +} + +/** + * Implements hook_features_enable_feature(). + */ +function user_permission_features_enable_feature($module) { + // If one feature contains both user roles and permissions, make sure the + // roles are reverted first so the permissions can be applied on them. + user_role_features_rebuild($module); + user_permission_features_rebuild($module); +} + +/** * Implements hook_features_rebuild(). * Iterate through default permissions and update the permissions map. * @@ -223,6 +263,20 @@ function user_role_features_revert($module) { } /** + * Implements hook_features_enable_feature(). + */ +function user_role_features_enable_feature($module) { + user_role_features_rebuild($module); +} + +/** + * Implements hook_features_enable_feature(). + */ +function user_role_features_enable_feature($module) { + user_role_features_rebuild($module); +} + +/** * Implements hook_features_rebuild(). */ function user_role_features_rebuild($module) {