comment.rules.inc 2.6 KB

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