rules_test.rules_defaults.inc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * @file Includes any rules integration provided by the module.
  4. */
  5. /**
  6. * Implements hook_default_rules_configuration().
  7. */
  8. function rules_test_default_rules_configuration() {
  9. $rule = rules_reaction_rule();
  10. $rule->label = 'example default rule';
  11. $rule->active = FALSE;
  12. $rule->event('node_update')
  13. ->condition(rules_condition('data_is', array('data:select' => 'node:status', 'value' => TRUE))->negate())
  14. ->condition('data_is', array('data:select' => 'node:type', 'value' => 'page'))
  15. ->action('drupal_message', array('message' => 'A node has been updated.'));
  16. $configs['rules_test_default_1'] = $rule;
  17. $action_set = rules_action_set(array('node' => array('type' => 'node', 'label' => 'Content')));
  18. $action_set->action('node_publish');
  19. $configs['rules_test_action_set'] = $action_set;
  20. // Test providing a rule using an export.
  21. $configs['rules_export_test'] = rules_import(_rules_export_get_test_export());
  22. // An action set used to test merging term parents.
  23. $configs['rules_retrieve_term_parents'] = rules_import('{ "rules_retrieve_term_parents" : {
  24. "LABEL" : "Retrieve term parents",
  25. "PLUGIN" : "action set",
  26. "REQUIRES" : [ "rules" ],
  27. "USES VARIABLES" : {
  28. "terms" : { "label" : "Terms", "type" : "list\u003ctaxonomy_term\u003e" },
  29. "term_parents" : {
  30. "label" : "Term parents",
  31. "type" : "list\u003ctaxonomy_term\u003e",
  32. "parameter" : false
  33. }
  34. },
  35. "ACTION SET" : [
  36. { "LOOP" : {
  37. "USING" : { "list" : [ "terms" ] },
  38. "ITEM" : { "current_term" : "Current term" },
  39. "DO" : [
  40. { "LOOP" : {
  41. "USING" : { "list" : [ "current-term:parent" ] },
  42. "ITEM" : { "current_parent" : "Current parent" },
  43. "DO" : [
  44. { "list_add" : {
  45. "list" : [ "term-parents" ],
  46. "item" : [ "current-parent" ],
  47. "unique" : 1
  48. }
  49. }
  50. ]
  51. }
  52. }
  53. ]
  54. }
  55. }
  56. ],
  57. "PROVIDES VARIABLES" : [ "term_parents" ]
  58. }
  59. }');
  60. return $configs;
  61. }
  62. /**
  63. * Defines the export of rule for testing import/export.
  64. */
  65. function _rules_export_get_test_export() {
  66. return '{ "rules_export_test" : {
  67. "LABEL" : "Test import rule2",
  68. "PLUGIN" : "reaction rule",
  69. "WEIGHT" : "-1",
  70. "ACTIVE" : false,
  71. "TAGS" : [ "bar", "baz", "foo" ],
  72. "REQUIRES" : [ "rules", "comment" ],
  73. "ON" : [ "comment_insert" ],
  74. "IF" : [
  75. { "OR" : [
  76. { "NOT node_is_sticky" : { "node" : [ "comment:node" ] } },
  77. { "node_is_of_type" : {
  78. "node" : [ "comment:node" ],
  79. "type" : { "value" : { "page" : "page" } }
  80. }
  81. },
  82. { "NOT AND" : [ { "OR" : [] } ] }
  83. ]
  84. }
  85. ],
  86. "DO" : [
  87. { "data_set" : {
  88. "data" : [ "comment:node:created" ],
  89. "value" : { "select" : "site:current-date", "date_offset" : { "value" : -604800 } }
  90. }
  91. },
  92. { "node_make_sticky" : { "node" : [ "comment:node" ] } },
  93. { "variable_add" : {
  94. "USING" : { "type" : "token", "value" : "error" },
  95. "PROVIDE" : { "variable_added" : { "level" : "Error level" } }
  96. }
  97. },
  98. { "drupal_message" : {
  99. "message" : "fein, [comment:node:title] has been made sticky!",
  100. "type" : [ "level" ]
  101. }
  102. },
  103. { "LOOP" : {
  104. "USING" : { "list" : [ "site:current-user:roles" ] },
  105. "ITEM" : { "current_role" : "Current role" },
  106. "DO" : [ { "drupal_message" : { "message" : [ "current-role" ] } } ]
  107. }
  108. }
  109. ]
  110. }
  111. }';
  112. }