rules_test.rules_defaults.inc 3.7 KB

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