features.features.inc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Implements hook_features_api().
  4. */
  5. function features_features_api() {
  6. return array(
  7. 'dependencies' => array(
  8. 'name' => 'Dependencies',
  9. 'feature_source' => TRUE,
  10. 'duplicates' => FEATURES_DUPLICATES_ALLOWED,
  11. ),
  12. );
  13. }
  14. /**
  15. * Implements hook_features_export_options().
  16. */
  17. function dependencies_features_export_options() {
  18. // Excluded modules.
  19. $excluded = drupal_required_modules();
  20. $options = array();
  21. foreach (features_get_modules() as $module_name => $info) {
  22. if (!in_array($module_name, $excluded) && $info->status && !empty($info->info)) {
  23. $options[$module_name] = $info->info['name'];
  24. }
  25. }
  26. return $options;
  27. }
  28. /**
  29. * Implements hook_features_export().
  30. */
  31. function dependencies_features_export($data, &$export, $module_name = '') {
  32. // Don't allow a module to depend upon itself.
  33. if (!empty($data[$module_name])) {
  34. unset($data[$module_name]);
  35. }
  36. // Clean up existing dependencies and merge.
  37. $export['dependencies'] = _features_export_minimize_dependencies($export['dependencies'], $module_name);
  38. $export['dependencies'] = array_merge($data, $export['dependencies']);
  39. $export['dependencies'] = array_unique($export['dependencies']);
  40. }
  41. /**
  42. * Implements hook_features_revert().
  43. */
  44. function dependencies_features_revert($module) {
  45. dependencies_features_rebuild($module);
  46. }
  47. /**
  48. * Implements hook_features_rebuild().
  49. * Ensure that all of a feature's dependencies are enabled.
  50. */
  51. function dependencies_features_rebuild($module) {
  52. $feature = features_get_features($module);
  53. if (!empty($feature->info['dependencies'])) {
  54. $install = array();
  55. foreach ($feature->info['dependencies'] as $dependency) {
  56. // Parse the dependency string into the module name and version information.
  57. $parsed_dependency = drupal_parse_dependency($dependency);
  58. $dependency = $parsed_dependency['name'];
  59. if (!module_exists($dependency)) {
  60. $install[] = $dependency;
  61. }
  62. }
  63. if (!empty($install)) {
  64. features_install_modules($install);
  65. }
  66. }
  67. }