|
1 <?php |
|
2 |
|
3 /** |
|
4 * @file |
|
5 * Mock module to aid in testing trigger.module. |
|
6 */ |
|
7 |
|
8 /** |
|
9 * Implements hook_action_info(). |
|
10 */ |
|
11 function trigger_test_action_info() { |
|
12 // Register an action that can be assigned to the trigger "cron". |
|
13 return array( |
|
14 'trigger_test_system_cron_action' => array( |
|
15 'type' => 'system', |
|
16 'label' => t('Cron test action'), |
|
17 'configurable' => FALSE, |
|
18 'triggers' => array('cron'), |
|
19 ), |
|
20 'trigger_test_system_cron_conf_action' => array( |
|
21 'type' => 'system', |
|
22 'label' => t('Cron test configurable action'), |
|
23 'configurable' => TRUE, |
|
24 'triggers' => array('cron'), |
|
25 ), |
|
26 'trigger_test_generic_action' => array( |
|
27 'type' => 'system', |
|
28 'label' => t('Generic test action'), |
|
29 'configurable' => FALSE, |
|
30 'triggers' => array( |
|
31 'taxonomy_term_insert', |
|
32 'taxonomy_term_update', |
|
33 'taxonomy_delete', |
|
34 'comment_insert', |
|
35 'comment_update', |
|
36 'comment_delete', |
|
37 'user_insert', |
|
38 'user_update', |
|
39 'user_delete', |
|
40 'user_login', |
|
41 'user_logout', |
|
42 'user_view', |
|
43 ), |
|
44 ), |
|
45 'trigger_test_generic_any_action' => array( |
|
46 'type' => 'system', |
|
47 'label' => t('Generic test action for any trigger'), |
|
48 'configurable' => FALSE, |
|
49 'triggers' => array('any'), |
|
50 ), |
|
51 ); |
|
52 } |
|
53 |
|
54 /** |
|
55 * Implements hook_trigger_info(). |
|
56 */ |
|
57 function trigger_test_trigger_info() { |
|
58 // Register triggers that this module provides. The first is an additional |
|
59 // node trigger and the second is our own, which should create a new tab |
|
60 // on the trigger assignment page. The last tests long trigger names. |
|
61 return array( |
|
62 'node' => array( |
|
63 'node_triggertest' => array( |
|
64 'label' => t('A test trigger is fired'), |
|
65 ), |
|
66 ), |
|
67 'trigger_test' => array( |
|
68 'trigger_test_triggertest' => array( |
|
69 'label' => t('Another test trigger is fired'), |
|
70 ), |
|
71 'trigger_test_we_sweat_it_out_in_the_streets_of_a_runaway_american_dream' => array( |
|
72 'label' => t('A test trigger with a name over 64 characters'), |
|
73 ), |
|
74 ), |
|
75 ); |
|
76 } |
|
77 |
|
78 /** |
|
79 * Action fired during the "cron run" trigger test. |
|
80 */ |
|
81 function trigger_test_system_cron_action() { |
|
82 // Indicate successful execution by setting a persistent variable. |
|
83 variable_set('trigger_test_system_cron_action', TRUE); |
|
84 } |
|
85 |
|
86 /** |
|
87 * Implement a configurable Drupal action. |
|
88 */ |
|
89 function trigger_test_system_cron_conf_action($object, $context) { |
|
90 // Indicate successful execution by incrementing a persistent variable. |
|
91 $value = variable_get('trigger_test_system_cron_conf_action', 0) + 1; |
|
92 variable_set('trigger_test_system_cron_conf_action', $value); |
|
93 } |
|
94 |
|
95 /** |
|
96 * Form for configurable test action. |
|
97 */ |
|
98 function trigger_test_system_cron_conf_action_form($context) { |
|
99 if (!isset($context['subject'])) { |
|
100 $context['subject'] = ''; |
|
101 } |
|
102 $form['subject'] = array( |
|
103 '#type' => 'textfield', |
|
104 '#default_value' => $context['subject'], |
|
105 ); |
|
106 return $form; |
|
107 } |
|
108 |
|
109 /** |
|
110 * Form submission handler for configurable test action. |
|
111 */ |
|
112 function trigger_test_system_cron_conf_action_submit($form, $form_state) { |
|
113 $form_values = $form_state['values']; |
|
114 // Process the HTML form to store configuration. The keyed array that |
|
115 // we return will be serialized to the database. |
|
116 $params = array( |
|
117 'subject' => $form_values['subject'], |
|
118 ); |
|
119 return $params; |
|
120 } |
|
121 |
|
122 /** |
|
123 * Action fired during the "taxonomy", "comment", and "user" trigger tests. |
|
124 */ |
|
125 function trigger_test_generic_action($context) { |
|
126 // Indicate successful execution by setting a persistent variable. |
|
127 variable_set('trigger_test_generic_action', TRUE); |
|
128 } |
|
129 |
|
130 /** |
|
131 * Action fired during the additional trigger tests. |
|
132 */ |
|
133 function trigger_test_generic_any_action($context) { |
|
134 // Indicate successful execution by setting a persistent variable. |
|
135 variable_set('trigger_test_generic_any_action', variable_get('trigger_test_generic_any_action', 0) + 1); |
|
136 } |