-
Notifications
You must be signed in to change notification settings - Fork 2
/
rules_web_remote.api.php
166 lines (152 loc) · 4.1 KB
/
rules_web_remote.api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
// $Id$
/**
* @file
* This file contains no working PHP code; it exists to provide additional
* documentation for doxygen as well as to document remotes in the standard
* Drupal manner.
*/
/**
* @addtogroup rules_hooks
* @{
*/
/**
* Define a remote endpoint type.
*
* This hook may be used to define a remote endpoint type, which users may
* use for configuring remote sites.
*
* @return
* An array of endpoint type definitions with the endpoint type names as keys.
* Each definition is represented by another array with the following keys:
* - label: The label of the endpoint type. Start capitalized. Required.
* - class: The actual implementation class for the endpoint type. This class
* has to implement the RulesWebRemoteEndpointInterface. Required.
*
* @see hook_rules_endpoint_types_alter()
* @see RulesWebRemoteEndpointInterface
*/
function hook_rules_endpoint_types() {
return array(
'rules_web_hook' => array(
'label' => t('Rules Web Hooks'),
'class' => 'RulesWebRemoteEndpointWebHooks',
),
);
}
/**
* Alter remote endpoint type definitions.
*
* @param $types
* The remote endpoint type definitions as returned from
* hook_rules_endpoint_types().
*
* @see hook_rules_endpoint_types()
*/
function hook_rules_endpoint_types_alter(&$types) {
}
/**
* Act on rules web remote sites being loaded from the database.
*
* This hook is invoked during rules web remotes loading, which is handled by
* entity_load(), via the EntityCRUDController.
*
* @param $remotes
* An array of rules web remote sites being loaded, keyed by id.
*/
function hook_rules_web_remote_load($remotes) {
$result = db_query('SELECT id, foo FROM {mytable} WHERE id IN(:ids)', array(':ids' => array_keys($remotes)));
foreach ($result as $record) {
$remotes[$record->id]->foo = $record->foo;
}
}
/**
* Respond to creation of a new rules web remote site.
*
* This hook is invoked after the rules web remote is inserted into the
* database.
*
* @param RulesWebRemote $remote
* The rules web remote site that is being created.
*/
function hook_rules_web_remote_insert($remote) {
db_insert('mytable')
->fields(array(
'id' => $remote->id,
'my_field' => $remote->myField,
))
->execute();
}
/**
* Act on a rules web remotes being inserted or updated.
*
* This hook is invoked before the rules web remote site is saved to the
* database.
*
* @param RulesWebRemote $remote
* The rules web remote site that is being inserted or updated.
*/
function hook_rules_web_remote_presave($remote) {
$remote->myField = 'foo';
}
/**
* Respond to updates to a rules web remote.
*
* This hook is invoked after the remote site has been updated in the database.
*
* @param RulesWebRemote $remote
* The rules web remote site that is being updated.
*/
function hook_rules_web_remote_update($remote) {
db_update('mytable')
->fields(array('my_field' => $remote->myField))
->condition('id', $remote->id)
->execute();
}
/**
* Respond to a remote site deletion.
*
* This hook is invoked after the remote site has been removed from the
* database.
*
* @param RulesWebRemote $remote
* The rules web remote site that is being deleted.
*/
function hook_rules_web_remote_delete($remote) {
db_delete('mytable')
->condition('id', $remote->id)
->execute();
}
/**
* Define default rules web remote sites.
*
* This hook is invoked when remote sites are loaded.
*
* @return
* An array of rules web remote sites with the remote site names as keys.
*
* @see hook_default_rules_web_remote_alter()
*/
function hook_default_rules_web_remote() {
$remote = new RulesWebRemote();
$remote->name = 'master';
$remote->label = 'The master site.';
$remote->url = 'http://master.example.com';
$remote->type = 'rules_web_hook';
$remotes[$remote->name] = $remote;
return $remotes;
}
/**
* Alter default remote sites.
*
* @param $remotes
* The default remote sites of all modules as returned from
* hook_default_rules_web_remote().
*
* @see hook_default_rules_web_remote()
*/
function hook_default_rules_web_remote_alter(&$remotes) {
}
/**
* @}
*/