-
Notifications
You must be signed in to change notification settings - Fork 6
/
cmrf_core.api.inc
152 lines (138 loc) · 4.9 KB
/
cmrf_core.api.inc
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
<?php
/**
* Example implementation of the provided API by this module
**/
/**
* Modify any CiviMRF connectors provided by other modules.
*
* This hook allows modules to modify, add, or remove connectors.
*
* If your module needs to provide a new connector (rather than modify an existing
* one) use hook_cmrf_core_connectors() instead.
* Note: do not forget to implement the connector class.
*
* @see hook_cmrf_core_default_profile()
*/
function hook_cmrf_core_connectors_alter(&$connectors) {
// Change the default curl implementation.
if (isset($connectors['curl'])) {
$connectors['curl']['callback'] = 'overide_curl_callback';
// The callback function overide_curl_callback will look like:
// function overide_curl_callback(\CMRF\Core\Core $core, $connector_id) {
// return new \MyCMRF\Connectors\OverridenCurlConnector($core, $connector_id);
// }
}
}
/**
* Provide module-based CiviMRF connectors for reuse throughout Drupal.
*
* This hook allows your module to provide CiviMRF Connectors. This may be useful if
* you require a different connector e.g. a connector to a rabbit mq implementation
*
* Note: do not forget to implement the connector class.
*
* @return array
* An array of connectors, keyed by the connector name.
*/
function hook_cmrf_core_connectors() {
$connectors['my_module_connector'] = array(
'label' => 'Custom Connector',
'callback' => 'my_module_connector_callback',
// The callback function my_module_connector_callback will look like:
//
// function my_module_connector_callback(\CMRF\Core\Core $core, $connector_id) {
// return new \MyCMRF\Connectors\MyConnector($core, $connector_id);
// }
);
return $connectors;
}
/**
* Modify any CiviMRF connection profiles provided by other modules or the user.
*
* This hook allows modules to modify, add, or remove profiles. This may
* be useful to modify default profiles provided by other modules or enforce
* that the api key and site key are not stored in the database but on the file system.
*
* Note that modifications to these profiles may negatively affect the user experience, such as if an
* api key is changed through this hook, the user may attempt to change
* the key but it will be immediately be reset.
*
* The best use of this hook is usually to modify default profiles, which are not
* editable by the user until they are overridden, so such interface
* contradictions will not occur. This hook can target default (or user) connection profiles
* by checking the $profile['storage'] property.
*
* If your module needs to provide a new profile (rather than modify an existing
* one) use hook_cmrf_core_default_profile() instead.
*
* @see hook_cmrf_core_default_profile()
*/
function hook_cmrf_core_profiles_alter(&$profiles) {
// Check that we only affect a default style.
if ($profiles['default']['storage'] == IMAGE_STORAGE_DEFAULT) {
// Add an additional effect to the thumbnail style.
$profiles['default']['url'] = 'https://the.secure.civicrm.org/sites/all/modules/';
$profiles['default']['site_key'] = '1237655hghhgh';
$profiles['default']['api_key'] = 'abcdef67899';
$profiles['default']['readonly'] = true;
}
}
/**
* Provide module-based CiviMRF profiles for reuse throughout Drupal.
*
* This hook allows your module to provide your own CiviMRF profiles. This may be useful if
* you require the credentials of the connection profile to be stored somewhere else.
* E.g. in an encrypted file.
*
* @return array
* An array of CiviMRF profiles, keyed by the profile name.
*/
function hook_cmrf_core_profiles() {
$profiles['mymodule_profile'] = array(
'label' => 'My module CiviMRF profile', // Required
'connector' => 'curl', // Required
'url' => 'https://your.civi.org/sites/all/modules/civicrm/extern/rest.php', // The rest end point
'site_key' => 'abcdefgh1234',
'api_key' => 'poiuyt09877',
'readonly' => true, // Whether the user can override and change the connector parameters.
);
return $profiles;
}
/**
* This hook gets fired after a call failed.
*
* @param \CMRF\Core\Call $call
*/
function hook_cmrf_core_call_failed(\CMRF\Core\Call $call) {
// Fire the trigger and get the related actions and execute them.
$aids = trigger_get_assigned_actions('failed_call');
if (!$aids) {
return;
}
$context = array(
'group' => 'cmrf',
'hook' => 'failed_call',
);
foreach ($aids as $aid => $info) {
actions_do($aid, $call, $context);
}
}
/**
* This hook gets fired after a call succeeded.
*
* @param \CMRF\Core\Call $call
*/
function hook_cmrf_core_call_done(\CMRF\Core\Call $call) {
// Fire the trigger and get the related actions and execute them.
$aids = trigger_get_assigned_actions('success_call');
if (!$aids) {
return;
}
$context = array(
'group' => 'cmrf',
'hook' => 'failed_call',
);
foreach ($aids as $aid => $info) {
actions_do($aid, $call, $context);
}
}