workflow_rules.node.inc 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. /**
  3. * @file
  4. * Rules integration for the Workflow module with Node API.
  5. */
  6. /**
  7. * Implements subfunction of hook_rules_event_info().
  8. */
  9. function _workflownode_rules_event_info() {
  10. $label = t('updated content');
  11. // Add variables for the 'node' type.
  12. $node_variables = rules_events_node_variables($label, TRUE);
  13. $events = array(
  14. 'workflow_state_changed' => array(
  15. 'group' => t('Workflow'),
  16. 'label' => t('Workflow state has changed'),
  17. 'variables' => $node_variables,
  18. ),
  19. 'workflow_comment_added' => array(
  20. 'group' => t('Workflow'),
  21. 'label' => t('Workflow comment was added, but state did not change'),
  22. 'variables' => $node_variables,
  23. ),
  24. );
  25. return $events;
  26. }
  27. /**
  28. * Implements subfunction of hook_rules_condition_info().
  29. */
  30. function _workflownode_rules_condition_info() {
  31. return array(
  32. 'workflow_check_transition' => array(
  33. 'group' => t('Workflow'),
  34. 'label' => t('Content makes a specific transition'),
  35. 'parameter' => array(
  36. 'node' => array(
  37. 'type' => 'node',
  38. 'label' => t('Node'),
  39. 'description' => t('The node whose workflow state is being checked.'),
  40. ),
  41. 'old_state' => array(
  42. 'type' => 'list<integer>',
  43. 'label' => t('Old workflow state'),
  44. 'options list' => '_workflow_rules_workflow_get_options',
  45. 'description' => t('The workflow state moved from.'),
  46. ),
  47. 'new_state' => array(
  48. 'type' => 'list<integer>',
  49. 'label' => t('New workflow state'),
  50. 'options list' => '_workflow_rules_workflow_get_options',
  51. 'description' => t('The workflow state moved to.'),
  52. ),
  53. ),
  54. 'base' => '_workflow_rules_node_check_transition',
  55. 'callbacks' => array(
  56. 'execute' => '_workflow_rules_node_check_transition',
  57. ),
  58. ),
  59. 'workflow_check_state' => array(
  60. 'group' => t('Workflow'),
  61. 'label' => t('Content has a workflow state'),
  62. 'parameter' => array(
  63. 'node' => array(
  64. 'type' => 'node',
  65. 'label' => t('Node'),
  66. 'description' => t('The node to compare the current workflow state of.'),
  67. ),
  68. 'workflow_state' => array(
  69. 'type' => 'list<integer>',
  70. 'label' => t('Compare workflow state'),
  71. 'options list' => '_workflow_rules_workflow_get_options',
  72. 'description' => t('The possible workflow states to compare against.'),
  73. ),
  74. ),
  75. 'base' => '_workflow_rules_node_check_state',
  76. 'callbacks' => array(
  77. 'execute' => '_workflow_rules_node_check_state',
  78. ),
  79. ),
  80. 'workflow_check_previous_state' => array(
  81. 'group' => t('Workflow'),
  82. 'label' => t('Content has a previous workflow state'),
  83. 'parameter' => array(
  84. 'node' => array(
  85. 'type' => 'node',
  86. 'label' => t('Node'),
  87. 'description' => t('The node to compare the previous workflow state of.'),
  88. ),
  89. 'workflow_state' => array(
  90. 'type' => 'list<integer>',
  91. 'label' => t('Compare workflow state'),
  92. 'options list' => '_workflow_rules_workflow_get_options',
  93. 'description' => t('The possible workflow states to compare against.'),
  94. ),
  95. ),
  96. 'base' => '_workflow_rules_node_check_previous_state',
  97. 'callbacks' => array(
  98. 'execute' => '_workflow_rules_node_check_previous_state',
  99. ),
  100. ),
  101. );
  102. }
  103. /**
  104. * Implements subfunction of hook_rules_action_info().
  105. */
  106. function _workflownode_rules_action_info() {
  107. $actions = array();
  108. // Warning: keep this action in line between Workflow Field and Workflow Node.
  109. $actions['workflow_rules_set_state'] = array(
  110. 'group' => t('Workflow'),
  111. 'label' => t('Set a Workflow state (with a comment)'),
  112. 'parameter' => array(
  113. 'node' => array(
  114. 'type' => 'entity',
  115. 'label' => t('Node'),
  116. 'description' => t('The node to set the current workflow state of.'),
  117. // 'save' => TRUE,
  118. ),
  119. /*
  120. //'field' => array(
  121. // 'type' => 'text', // WORKFLOWFIELD_PROPERTY_TYPE,
  122. // 'label' => t('Workflow field to set'),
  123. // 'description' => t('The workflow field to set.'),
  124. // 'restriction' => 'selector',
  125. // 'allow null' => TRUE,
  126. //),
  127. */
  128. 'workflow_state' => array(
  129. 'type' => 'list<integer>',
  130. 'label' => t('New workflow state'),
  131. 'options list' => '_workflow_rules_workflow_get_options',
  132. 'description' => t('The workflow state to set (select only one).'),
  133. ),
  134. 'workflow_comment' => array(
  135. 'type' => 'text',
  136. 'label' => t('Workflow Comment'),
  137. 'description' => t('The workflow comment to set.'),
  138. 'optional' => TRUE,
  139. ),
  140. ),
  141. 'named parameter' => TRUE,
  142. 'base' => '_workflow_rules_set_state',
  143. 'callbacks' => array(
  144. 'execute' => '_workflow_rules_set_state',
  145. ),
  146. );
  147. return $actions;
  148. }