rules.features.inc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * @file
  4. * Provides Features integration for the Rules module, based upon the features
  5. * integration provided by the Entity API.
  6. */
  7. /**
  8. * Controller handling the features integration.
  9. */
  10. class RulesFeaturesController extends EntityDefaultFeaturesController {
  11. /**
  12. * Defines the result for hook_features_api().
  13. */
  14. public function api() {
  15. $info = parent::api();
  16. $info['rules_config']['default_file'] = FEATURES_DEFAULTS_CUSTOM;
  17. $info['rules_config']['default_filename'] = 'rules_defaults';
  18. return $info;
  19. }
  20. /**
  21. * Generates the result for hook_features_export().
  22. * Overridden to add in rules specific stuff.
  23. */
  24. public function export($data, &$export, $module_name = '') {
  25. $pipe = parent::export($data, $export, $module_name);
  26. foreach (entity_load_multiple_by_name($this->type, $data) as $name => $rules_config) {
  27. // Add in the dependencies.
  28. $export['dependencies'] += drupal_map_assoc($rules_config->dependencies());
  29. // Add in plugin / element specific additions.
  30. $iterator = new RecursiveIteratorIterator($rules_config, RecursiveIteratorIterator::SELF_FIRST);
  31. foreach ($iterator as $element) {
  32. if ($element->facesAs('RulesPluginFeaturesIntegrationInterace')) {
  33. // Directly use __call() so we cann pass $export by reference.
  34. $element->__call('features_export', array(&$export, &$pipe, $module_name));
  35. }
  36. }
  37. }
  38. return $pipe;
  39. }
  40. }
  41. /**
  42. * Default extension callback used as default for the abstract plugin class.
  43. * Actions / conditions may override this with their own implementation, which
  44. * actually does something.
  45. *
  46. * @see RulesPluginFeaturesIntegrationInterace
  47. */
  48. function rules_features_abstract_default_features_export(&$export, &$pipe, $module_name = '', $element) {
  49. }
  50. /**
  51. * Interface that allows rules plugins or actions/conditions to customize the
  52. * features export by implementing the interface using the faces extensions
  53. * mechanism.
  54. *
  55. * @see hook_rules_plugin_info()
  56. * @see hook_rules_action_info()
  57. */
  58. interface RulesPluginFeaturesIntegrationInterace {
  59. /**
  60. * Allows customizing the features export for a given rule element.
  61. */
  62. function features_export(&$export, &$pipe, $module_name = '');
  63. }