rules.features.inc 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * @file
  4. * Provides Features integration for the Rules module.
  5. *
  6. * This code is based upon the features integration provided by the Entity API.
  7. */
  8. /**
  9. * Controller handling the features integration.
  10. */
  11. class RulesFeaturesController extends EntityDefaultFeaturesController {
  12. /**
  13. * Defines the result for hook_features_api().
  14. */
  15. public function api() {
  16. $info = parent::api();
  17. $info['rules_config']['default_file'] = FEATURES_DEFAULTS_CUSTOM;
  18. $info['rules_config']['default_filename'] = 'rules_defaults';
  19. return $info;
  20. }
  21. /**
  22. * Generates the result for hook_features_export().
  23. *
  24. * Overridden to add in rules-specific stuff.
  25. */
  26. public function export($data, &$export, $module_name = '') {
  27. $pipe = parent::export($data, $export, $module_name);
  28. foreach (entity_load_multiple_by_name($this->type, $data) as $name => $rules_config) {
  29. // Add in the dependencies.
  30. $export['dependencies'] += drupal_map_assoc($rules_config->dependencies());
  31. // Add in plugin / element specific additions.
  32. $iterator = new RecursiveIteratorIterator($rules_config, RecursiveIteratorIterator::SELF_FIRST);
  33. foreach ($iterator as $element) {
  34. if ($element->facesAs('RulesPluginFeaturesIntegrationInterface')) {
  35. // Directly use __call() so we can pass $export by reference.
  36. $element->__call('features_export', array(&$export, &$pipe, $module_name));
  37. }
  38. }
  39. }
  40. return $pipe;
  41. }
  42. }
  43. /**
  44. * Default extension callback used as default for the abstract plugin class.
  45. *
  46. * Actions and conditions may override this with an implementation which
  47. * actually does something.
  48. *
  49. * @see RulesPluginFeaturesIntegrationInterface
  50. */
  51. function rules_features_abstract_default_features_export(&$export, &$pipe, $module_name = '', $element) {
  52. // Do nothing.
  53. }
  54. /**
  55. * Interface to give features access to the faces extensions mechanism.
  56. *
  57. * Interface that allows rules plugins or actions/conditions to customize the
  58. * features export by implementing the interface using the faces extensions
  59. * mechanism.
  60. *
  61. * @see hook_rules_plugin_info()
  62. * @see hook_rules_action_info()
  63. */
  64. interface RulesPluginFeaturesIntegrationInterface {
  65. /**
  66. * Allows customizing the features export for a given rule element.
  67. */
  68. public function features_export(&$export, &$pipe, $module_name = '');
  69. }
  70. /**
  71. * Interface for backwards compatibility with older versions of Rules.
  72. *
  73. * Mis-spelled interface provided so that contributed modules which were
  74. * implementing the wrong spelling (corrected in Rules 7.x-2.12) will not stop
  75. * working now that the interface is spelled correctly.
  76. *
  77. * @todo Remove this when we can be sure that no contributed modules are
  78. * still using the wrong spelling.
  79. */
  80. interface RulesPluginFeaturesIntegrationInterace extends RulesPluginFeaturesIntegrationInterface {
  81. }