-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrules_modal.module
95 lines (86 loc) · 2.22 KB
/
rules_modal.module
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
<?php
/**
* Implements hook_menu
*/
function rules_modal_menu() {
$items['rules_modal/%'] = array(
'page callback' => 'rules_modal_form_submit_ajax',
'page arguments' => array(1),
'access callback' => TRUE,
);
return $items;
}
/**
* Implements hook_init()
*/
function rules_modal_init() {
ctools_include('modal');
ctools_include('ajax');
}
/**
* Implements hook_rules_event_info
*/
function rules_modal_rules_event_info() {
$items = array(
'rules_modal_form_submit' => array(
'label' => t('Form Submission'),
'group' => t('Rules Modal'),
'variables' => array(
'form_id' => array(
'label' => t('Form Id'),
'type' => 'text'
)
)
)
);
return $items;
}
/**
* Implements hook_rules_action_info
*/
function rules_modal_rules_action_info() {
return array(
'rules_modal' => array(
'label' => t('Display a Modal'),
'parameter' => array(
'modal_callback' => array(
'type' => 'text',
'label' => t('Select A Modal'),
'description' => t('Select the modal to display when this action runs.'),
'options list' => 'rules_modal_callback_options',
'restriction' => 'input',
),
),
'group' => t('Rules Modal'),
'base' => 'rules_modal',
'callbacks' => array( ),
),
);
}
function rules_modal($modal_callback = '') {
drupal_add_js('Drupal.behaviors.rules_modal_display.show("'. $modal_callback .'");', 'inline');
}
function rules_modal_callback_options() {
$options = array( );
$callbacks = module_invoke_all('rules_modal_info');
foreach($callbacks as $id => $callback) {
$options[$callback['path']] = $callback['title'];
}
return $options;
}
/**
* Responds to a form submit, and checks first if there is some sort of action that needs to fire.
*/
function rules_modal_form_submit_ajax($form_id, $form_data = NULL) {
$form_id = str_replace('-', '_', $form_id);
$form_data = $_POST['data'];
$callbacks = module_invoke_all('rules_modal_form_response', $form_id, $form_data);
// trigger the event, we need to return the resulting response in a
// sensible json data packet.
print drupal_json_output(
array(
'continue' => TRUE,
)
);
exit();
}