1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Helper module for the Common tests.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Implements hook_menu().
|
10
|
*/
|
11
|
function common_test_menu() {
|
12
|
$items['common-test/drupal_goto'] = array(
|
13
|
'title' => 'Drupal Goto',
|
14
|
'page callback' => 'common_test_drupal_goto_land',
|
15
|
'access arguments' => array('access content'),
|
16
|
'type' => MENU_CALLBACK,
|
17
|
);
|
18
|
$items['common-test/drupal_goto/fail'] = array(
|
19
|
'title' => 'Drupal Goto',
|
20
|
'page callback' => 'common_test_drupal_goto_land_fail',
|
21
|
'access arguments' => array('access content'),
|
22
|
'type' => MENU_CALLBACK,
|
23
|
);
|
24
|
$items['common-test/drupal_goto/redirect'] = array(
|
25
|
'title' => 'Drupal Goto',
|
26
|
'page callback' => 'common_test_drupal_goto_redirect',
|
27
|
'access arguments' => array('access content'),
|
28
|
'type' => MENU_CALLBACK,
|
29
|
);
|
30
|
$items['common-test/drupal_goto/redirect_advanced'] = array(
|
31
|
'title' => 'Drupal Goto',
|
32
|
'page callback' => 'common_test_drupal_goto_redirect_advanced',
|
33
|
'access arguments' => array('access content'),
|
34
|
'type' => MENU_CALLBACK,
|
35
|
);
|
36
|
$items['common-test/drupal_goto/redirect_fail'] = array(
|
37
|
'title' => 'Drupal Goto Failure',
|
38
|
'page callback' => 'drupal_goto',
|
39
|
'page arguments' => array('common-test/drupal_goto/fail'),
|
40
|
'access arguments' => array('access content'),
|
41
|
'type' => MENU_CALLBACK,
|
42
|
);
|
43
|
$items['common-test/destination'] = array(
|
44
|
'title' => 'Drupal Get Destination',
|
45
|
'page callback' => 'common_test_destination',
|
46
|
'access arguments' => array('access content'),
|
47
|
'type' => MENU_CALLBACK,
|
48
|
);
|
49
|
$items['common-test/query-string'] = array(
|
50
|
'title' => 'Test querystring',
|
51
|
'page callback' => 'common_test_js_and_css_querystring',
|
52
|
'access arguments' => array('access content'),
|
53
|
'type' => MENU_CALLBACK,
|
54
|
);
|
55
|
return $items;
|
56
|
}
|
57
|
|
58
|
/**
|
59
|
* Redirect using drupal_goto().
|
60
|
*/
|
61
|
function common_test_drupal_goto_redirect() {
|
62
|
drupal_goto('common-test/drupal_goto');
|
63
|
}
|
64
|
|
65
|
/**
|
66
|
* Redirect using drupal_goto().
|
67
|
*/
|
68
|
function common_test_drupal_goto_redirect_advanced() {
|
69
|
drupal_goto('common-test/drupal_goto', array('query' => array('foo' => '123')), 301);
|
70
|
}
|
71
|
|
72
|
/**
|
73
|
* Landing page for drupal_goto().
|
74
|
*/
|
75
|
function common_test_drupal_goto_land() {
|
76
|
print "drupal_goto";
|
77
|
}
|
78
|
|
79
|
/**
|
80
|
* Fail landing page for drupal_goto().
|
81
|
*/
|
82
|
function common_test_drupal_goto_land_fail() {
|
83
|
print "drupal_goto_fail";
|
84
|
}
|
85
|
|
86
|
/**
|
87
|
* Implements hook_drupal_goto_alter().
|
88
|
*/
|
89
|
function common_test_drupal_goto_alter(&$path, &$options, &$http_response_code) {
|
90
|
if ($path == 'common-test/drupal_goto/fail') {
|
91
|
$path = 'common-test/drupal_goto/redirect';
|
92
|
}
|
93
|
}
|
94
|
|
95
|
/**
|
96
|
* Print destination query parameter.
|
97
|
*/
|
98
|
function common_test_destination() {
|
99
|
$destination = drupal_get_destination();
|
100
|
print "The destination: " . check_plain($destination['destination']);
|
101
|
}
|
102
|
|
103
|
/**
|
104
|
* Applies #printed to an element to help test #pre_render.
|
105
|
*/
|
106
|
function common_test_drupal_render_printing_pre_render($elements) {
|
107
|
$elements['#printed'] = TRUE;
|
108
|
return $elements;
|
109
|
}
|
110
|
|
111
|
/**
|
112
|
* Implements hook_TYPE_alter().
|
113
|
*/
|
114
|
function common_test_drupal_alter_alter(&$data, &$arg2 = NULL, &$arg3 = NULL) {
|
115
|
// Alter first argument.
|
116
|
if (is_array($data)) {
|
117
|
$data['foo'] = 'Drupal';
|
118
|
}
|
119
|
elseif (is_object($data)) {
|
120
|
$data->foo = 'Drupal';
|
121
|
}
|
122
|
// Alter second argument, if present.
|
123
|
if (isset($arg2)) {
|
124
|
if (is_array($arg2)) {
|
125
|
$arg2['foo'] = 'Drupal';
|
126
|
}
|
127
|
elseif (is_object($arg2)) {
|
128
|
$arg2->foo = 'Drupal';
|
129
|
}
|
130
|
}
|
131
|
// Try to alter third argument, if present.
|
132
|
if (isset($arg3)) {
|
133
|
if (is_array($arg3)) {
|
134
|
$arg3['foo'] = 'Drupal';
|
135
|
}
|
136
|
elseif (is_object($arg3)) {
|
137
|
$arg3->foo = 'Drupal';
|
138
|
}
|
139
|
}
|
140
|
}
|
141
|
|
142
|
/**
|
143
|
* Implements hook_TYPE_alter() on behalf of Bartik theme.
|
144
|
*
|
145
|
* Same as common_test_drupal_alter_alter(), but here, we verify that themes
|
146
|
* can also alter and come last.
|
147
|
*/
|
148
|
function bartik_drupal_alter_alter(&$data, &$arg2 = NULL, &$arg3 = NULL) {
|
149
|
// Alter first argument.
|
150
|
if (is_array($data)) {
|
151
|
$data['foo'] .= ' theme';
|
152
|
}
|
153
|
elseif (is_object($data)) {
|
154
|
$data->foo .= ' theme';
|
155
|
}
|
156
|
// Alter second argument, if present.
|
157
|
if (isset($arg2)) {
|
158
|
if (is_array($arg2)) {
|
159
|
$arg2['foo'] .= ' theme';
|
160
|
}
|
161
|
elseif (is_object($arg2)) {
|
162
|
$arg2->foo .= ' theme';
|
163
|
}
|
164
|
}
|
165
|
// Try to alter third argument, if present.
|
166
|
if (isset($arg3)) {
|
167
|
if (is_array($arg3)) {
|
168
|
$arg3['foo'] .= ' theme';
|
169
|
}
|
170
|
elseif (is_object($arg3)) {
|
171
|
$arg3->foo .= ' theme';
|
172
|
}
|
173
|
}
|
174
|
}
|
175
|
|
176
|
/**
|
177
|
* Implements hook_TYPE_alter() on behalf of block module.
|
178
|
*
|
179
|
* This is for verifying that drupal_alter(array(TYPE1, TYPE2), ...) allows
|
180
|
* hook_module_implements_alter() to affect the order in which module
|
181
|
* implementations are executed.
|
182
|
*/
|
183
|
function block_drupal_alter_foo_alter(&$data, &$arg2 = NULL, &$arg3 = NULL) {
|
184
|
$data['foo'] .= ' block';
|
185
|
}
|
186
|
|
187
|
/**
|
188
|
* Implements hook_module_implements_alter().
|
189
|
*
|
190
|
* @see block_drupal_alter_foo_alter()
|
191
|
*/
|
192
|
function common_test_module_implements_alter(&$implementations, $hook) {
|
193
|
// For drupal_alter(array('drupal_alter', 'drupal_alter_foo'), ...), make the
|
194
|
// block module implementations run after all the other modules. Note that
|
195
|
// when drupal_alter() is called with an array of types, the first type is
|
196
|
// considered primary and controls the module order.
|
197
|
if ($hook == 'drupal_alter_alter' && isset($implementations['block'])) {
|
198
|
$group = $implementations['block'];
|
199
|
unset($implementations['block']);
|
200
|
$implementations['block'] = $group;
|
201
|
}
|
202
|
}
|
203
|
|
204
|
/**
|
205
|
* Implements hook_theme().
|
206
|
*/
|
207
|
function common_test_theme() {
|
208
|
return array(
|
209
|
'common_test_foo' => array(
|
210
|
'variables' => array('foo' => 'foo', 'bar' => 'bar'),
|
211
|
),
|
212
|
);
|
213
|
}
|
214
|
|
215
|
/**
|
216
|
* Theme function for testing drupal_render() theming.
|
217
|
*/
|
218
|
function theme_common_test_foo($variables) {
|
219
|
return $variables['foo'] . $variables['bar'];
|
220
|
}
|
221
|
|
222
|
/**
|
223
|
* Implements hook_library_alter().
|
224
|
*/
|
225
|
function common_test_library_alter(&$libraries, $module) {
|
226
|
if ($module == 'system' && isset($libraries['farbtastic'])) {
|
227
|
// Change the title of Farbtastic to "Farbtastic: Altered Library".
|
228
|
$libraries['farbtastic']['title'] = 'Farbtastic: Altered Library';
|
229
|
// Make Farbtastic depend on jQuery Form to test library dependencies.
|
230
|
$libraries['farbtastic']['dependencies'][] = array('system', 'form');
|
231
|
}
|
232
|
}
|
233
|
|
234
|
/**
|
235
|
* Implements hook_library().
|
236
|
*
|
237
|
* Adds Farbtastic in a different version.
|
238
|
*/
|
239
|
function common_test_library() {
|
240
|
$libraries['farbtastic'] = array(
|
241
|
'title' => 'Custom Farbtastic Library',
|
242
|
'website' => 'http://code.google.com/p/farbtastic/',
|
243
|
'version' => '5.3',
|
244
|
'js' => array(
|
245
|
'misc/farbtastic/farbtastic.js' => array(),
|
246
|
),
|
247
|
'css' => array(
|
248
|
'misc/farbtastic/farbtastic.css' => array(),
|
249
|
),
|
250
|
);
|
251
|
return $libraries;
|
252
|
}
|
253
|
|
254
|
/**
|
255
|
* Adds a JavaScript file and a CSS file with a query string appended.
|
256
|
*/
|
257
|
function common_test_js_and_css_querystring() {
|
258
|
drupal_add_js(drupal_get_path('module', 'node') . '/node.js');
|
259
|
drupal_add_css(drupal_get_path('module', 'node') . '/node.css');
|
260
|
// A relative URI may have a query string.
|
261
|
drupal_add_css('/' . drupal_get_path('module', 'node') . '/node-fake.css?arg1=value1&arg2=value2');
|
262
|
return '';
|
263
|
}
|
264
|
|
265
|
/**
|
266
|
* Implements hook_cron().
|
267
|
*
|
268
|
* System module should handle if a module does not catch an exception and keep
|
269
|
* cron going.
|
270
|
*
|
271
|
* @see common_test_cron_helper()
|
272
|
*
|
273
|
*/
|
274
|
function common_test_cron() {
|
275
|
throw new Exception(t('Uncaught exception'));
|
276
|
}
|