synonyms.features.inc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * @file
  4. * Synonyms module integration with Features.
  5. */
  6. /**
  7. * Implements hook_features_export().
  8. */
  9. function synonyms_features_export($data, &$export, $module_name) {
  10. $pipe = array();
  11. $export['features']['synonyms'] = array();
  12. foreach ($data as $v) {
  13. list($entity_type, $bundle, $provider, $behavior) = explode(':', $v);
  14. $behavior_definition = synonyms_behaviors();
  15. $behavior_definition = $behavior_definition[$behavior];
  16. $export['dependencies'][] = $behavior_definition['module'];
  17. $export['features']['synonyms'][$v] = $v;
  18. $behavior_implementation = synonyms_behavior_get_all_enabled($entity_type, $bundle, $provider, $behavior);
  19. $behavior_implementation = reset($behavior_implementation);
  20. $provider_info = synonyms_behavior_implementation_info($entity_type, $bundle, $behavior);
  21. $provider_info = $provider_info[$provider];
  22. $export['dependencies'][] = $provider_info['module'];
  23. $pipe = array_merge_recursive($pipe, $behavior_implementation['object']->featuresExportPipe());
  24. }
  25. $export['dependencies'][] = 'synonyms';
  26. $export['dependencies'] = drupal_map_assoc(array_unique($export['dependencies']));
  27. return $pipe;
  28. }
  29. /**
  30. * Implements hook_features_export_options().
  31. */
  32. function synonyms_features_export_options() {
  33. $options = array();
  34. foreach (synonyms_behavior_get_all_enabled() as $behavior_implementation) {
  35. $key = array(
  36. $behavior_implementation['entity_type'],
  37. $behavior_implementation['bundle'],
  38. $behavior_implementation['provider'],
  39. $behavior_implementation['behavior'],
  40. );
  41. if ($behavior_implementation['entity_type'] == $behavior_implementation['bundle']) {
  42. $label = t('@entity_type @provider @behavior', array(
  43. '@entity_type' => $behavior_implementation['entity_type'],
  44. '@provider' => $behavior_implementation['label'],
  45. '@behavior' => $behavior_implementation['behavior'],
  46. ));
  47. }
  48. else {
  49. $label = t('@entity_type @bundle @provider @behavior', array(
  50. '@entity_type' => $behavior_implementation['entity_type'],
  51. '@bundle' => $behavior_implementation['bundle'],
  52. '@provider' => $behavior_implementation['label'],
  53. '@behavior' => $behavior_implementation['behavior'],
  54. ));
  55. }
  56. $options[implode(':', $key)] = $label;
  57. }
  58. return $options;
  59. }
  60. /**
  61. * Implements hook_features_export_render().
  62. */
  63. function synonyms_features_export_render($module_name, $data, $export = NULL) {
  64. $code = array();
  65. $code[] = ' $synonyms = array();';
  66. foreach ($data as $name) {
  67. list($entity_type, $bundle, $provider, $behavior) = explode(':', $name);
  68. $behavior_implementation = synonyms_behavior_get_all_enabled($entity_type, $bundle, $provider, $behavior);
  69. $behavior_implementation = reset($behavior_implementation);
  70. if (is_array($behavior_implementation)) {
  71. $behavior_implementation = array_intersect_key($behavior_implementation, drupal_map_assoc(array(
  72. 'entity_type', 'bundle', 'provider', 'settings', 'behavior',
  73. )));
  74. }
  75. $code[] = " \$synonyms['{$name}'] = " . features_var_export($behavior_implementation, ' ') .";";
  76. }
  77. $code[] = " return \$synonyms;";
  78. $code = implode("\n", $code);
  79. return array('default_synonyms' => $code);
  80. }
  81. /**
  82. * Implements hook_features_revert().
  83. */
  84. function synonyms_features_revert($module_name) {
  85. $synonyms = module_invoke($module_name, 'default_synonyms');
  86. foreach ($synonyms as $v) {
  87. synonyms_behavior_implementation_save($v);
  88. }
  89. }
  90. /**
  91. * Implements hook_features_rebuild().
  92. */
  93. function synonyms_features_rebuild($module_name) {
  94. $synonyms = module_invoke($module_name, 'default_synonyms');
  95. foreach ($synonyms as $v) {
  96. synonyms_behavior_implementation_save($v);
  97. }
  98. }