hierarchical_select.features.inc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * @file
  4. * Integration with the features module.
  5. */
  6. /**
  7. * Implements hook_features_export().
  8. */
  9. function hierarchical_select_features_export($data, &$export, $module_name) {
  10. // Add hierarchical_select dependency.
  11. $export['dependencies']['hierarchical_select'] = 'hierarchical_select';
  12. // Retrieve dependencies from all information items.
  13. $dependencies = array();
  14. foreach (module_implements('hierarchical_select_config_info') as $module) {
  15. $configs = module_invoke($module, 'hierarchical_select_config_info');
  16. foreach ($configs as $config_id => $config) {
  17. $dependencies[$config_id] = $module;
  18. }
  19. }
  20. // Add features and dependencies.
  21. foreach ($data as $config_id) {
  22. $export['features']['hierarchical_select'][$config_id] = $config_id;
  23. if (isset($dependencies[$config_id])) {
  24. $module = $dependencies[$config_id];
  25. $export['dependencies'][$module] = $module;
  26. }
  27. }
  28. return array();
  29. }
  30. /**
  31. * Implements hook_features_export_options().
  32. */
  33. function hierarchical_select_features_export_options() {
  34. // Retrieve all information items.
  35. $info_items = array();
  36. foreach (module_implements('hierarchical_select_config_info') as $module) {
  37. $info_items = array_merge_recursive($info_items, module_invoke($module, 'hierarchical_select_config_info'));
  38. }
  39. // Process the retrieved information into options.
  40. $options = array();
  41. foreach ($info_items as $id => $item) {
  42. $config_id = $item['config_id'];
  43. $options[$config_id] = $item['hierarchy type'] . ': ' . $item['hierarchy'] . ' - ' . $item['context type'] . (!empty($item['context']) ? ': ' . $item['context'] : '');
  44. }
  45. return $options;
  46. }
  47. /**
  48. * Implements hook_features_export_render().
  49. */
  50. function hierarchical_select_features_export_render($module, $data) {
  51. module_load_include('inc', 'hierarchical_select', 'includes/common');
  52. module_load_include('inc', 'hierarchical_select', 'hierarchical_select.admin');
  53. $code = array();
  54. $code[] = '$configs = array();';
  55. foreach ($data as $config_id) {
  56. $config = hierarchical_select_common_config_get($config_id);
  57. $config['config_id'] = $config_id;
  58. $code[] = _hierarchical_select_create_export_code($config);
  59. $code[] = "\$configs['{$config_id}'] = \$config;";
  60. }
  61. $code[] = "return \$configs;";
  62. $code = implode("\n", $code);
  63. return array('hierarchical_select_default_configs' => $code);
  64. }
  65. /**
  66. * Implements hook_features_revert().
  67. */
  68. function hierarchical_select_features_revert($module) {
  69. hierarchical_select_features_rebuild($module);
  70. }
  71. /**
  72. * Implements hook_features_rebuild().
  73. */
  74. function hierarchical_select_features_rebuild($module) {
  75. module_load_include('inc', 'hierarchical_select', 'includes/common');
  76. $configs = features_get_default('hierarchical_select', $module);
  77. if (!empty($configs)) {
  78. // Apply the configuration.
  79. require_once(drupal_get_path('module', 'hierarchical_select') .'/includes/common.inc');
  80. foreach ($configs as $config_id => $config) {
  81. hierarchical_select_common_config_set($config_id, $config);
  82. }
  83. }
  84. }