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