comment.rules.inc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * @file rules integration for the comment module
  4. *
  5. * @addtogroup rules
  6. * @{
  7. */
  8. /**
  9. * Implementation of hook_rules_event_info().
  10. */
  11. function rules_comment_event_info() {
  12. $defaults = array(
  13. 'group' => t('comment'),
  14. 'module' => 'comment',
  15. 'access callback' => 'rules_comment_integration_access',
  16. 'class' => 'RulesCommentEventHandler',
  17. );
  18. return array(
  19. 'comment_insert' => $defaults + array(
  20. 'label' => t('After saving a new comment'),
  21. 'variables' => array(
  22. 'comment' => array('type' => 'comment', 'label' => t('created comment')),
  23. ),
  24. ),
  25. 'comment_update' => $defaults + array(
  26. 'label' => t('After updating an existing comment'),
  27. 'variables' => array(
  28. 'comment' => array('type' => 'comment', 'label' => t('updated comment')),
  29. 'comment_unchanged' => array('type' => 'comment', 'label' => t('unchanged comment'), 'handler' => 'rules_events_entity_unchanged'),
  30. ),
  31. ),
  32. 'comment_presave' => $defaults + array(
  33. 'label' => t('Before saving a comment'),
  34. 'variables' => array(
  35. 'comment' => array('type' => 'comment', 'label' => t('saved comment'), 'skip save' => TRUE),
  36. 'comment_unchanged' => array('type' => 'comment', 'label' => t('unchanged comment'), 'handler' => 'rules_events_entity_unchanged'),
  37. ),
  38. ),
  39. 'comment_view' => $defaults + array(
  40. 'label' => t('A comment is viewed'),
  41. 'variables' => array(
  42. 'comment' => array('type' => 'comment', 'label' => t('viewed comment')),
  43. ),
  44. 'help' => t("Note that if drupal's page cache is enabled, this event won't be generated for pages served from cache."),
  45. ),
  46. 'comment_delete' => $defaults + array(
  47. 'label' => t('After deleting a comment'),
  48. 'variables' => array(
  49. 'comment' => array('type' => 'comment', 'label' => t('deleted comment')),
  50. ),
  51. ),
  52. );
  53. }
  54. /**
  55. * Comment integration access callback.
  56. */
  57. function rules_comment_integration_access($type, $name) {
  58. if ($type == 'event' || $type == 'condition') {
  59. return entity_access('view', 'comment');
  60. }
  61. }
  62. /**
  63. * Event handler support comment bundle event settings.
  64. */
  65. class RulesCommentEventHandler extends RulesEventHandlerEntityBundle {
  66. /**
  67. * Returns the label to use for the bundle property.
  68. *
  69. * @return string
  70. */
  71. protected function getBundlePropertyLabel() {
  72. return t('type');
  73. }
  74. }
  75. /**
  76. * @}
  77. */