1 |
85ad3d82
|
Assos Assos
|
<?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 |
134c7813
|
Mathieu Schiano
|
/**
|
96 |
|
|
* Implements hook_init().
|
97 |
|
|
*/
|
98 |
|
|
function common_test_init() {
|
99 |
|
|
if (variable_get('common_test_redirect_current_path', FALSE)) {
|
100 |
|
|
drupal_goto(current_path());
|
101 |
|
|
}
|
102 |
|
|
}
|
103 |
|
|
|
104 |
85ad3d82
|
Assos Assos
|
/**
|
105 |
|
|
* Print destination query parameter.
|
106 |
|
|
*/
|
107 |
|
|
function common_test_destination() {
|
108 |
|
|
$destination = drupal_get_destination();
|
109 |
|
|
print "The destination: " . check_plain($destination['destination']);
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
/**
|
113 |
|
|
* Applies #printed to an element to help test #pre_render.
|
114 |
|
|
*/
|
115 |
|
|
function common_test_drupal_render_printing_pre_render($elements) {
|
116 |
|
|
$elements['#printed'] = TRUE;
|
117 |
|
|
return $elements;
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
/**
|
121 |
|
|
* Implements hook_TYPE_alter().
|
122 |
|
|
*/
|
123 |
|
|
function common_test_drupal_alter_alter(&$data, &$arg2 = NULL, &$arg3 = NULL) {
|
124 |
|
|
// Alter first argument.
|
125 |
|
|
if (is_array($data)) {
|
126 |
|
|
$data['foo'] = 'Drupal';
|
127 |
|
|
}
|
128 |
|
|
elseif (is_object($data)) {
|
129 |
|
|
$data->foo = 'Drupal';
|
130 |
|
|
}
|
131 |
|
|
// Alter second argument, if present.
|
132 |
|
|
if (isset($arg2)) {
|
133 |
|
|
if (is_array($arg2)) {
|
134 |
|
|
$arg2['foo'] = 'Drupal';
|
135 |
|
|
}
|
136 |
|
|
elseif (is_object($arg2)) {
|
137 |
|
|
$arg2->foo = 'Drupal';
|
138 |
|
|
}
|
139 |
|
|
}
|
140 |
|
|
// Try to alter third argument, if present.
|
141 |
|
|
if (isset($arg3)) {
|
142 |
|
|
if (is_array($arg3)) {
|
143 |
|
|
$arg3['foo'] = 'Drupal';
|
144 |
|
|
}
|
145 |
|
|
elseif (is_object($arg3)) {
|
146 |
|
|
$arg3->foo = 'Drupal';
|
147 |
|
|
}
|
148 |
|
|
}
|
149 |
|
|
}
|
150 |
|
|
|
151 |
|
|
/**
|
152 |
|
|
* Implements hook_TYPE_alter() on behalf of Bartik theme.
|
153 |
|
|
*
|
154 |
|
|
* Same as common_test_drupal_alter_alter(), but here, we verify that themes
|
155 |
|
|
* can also alter and come last.
|
156 |
|
|
*/
|
157 |
|
|
function bartik_drupal_alter_alter(&$data, &$arg2 = NULL, &$arg3 = NULL) {
|
158 |
|
|
// Alter first argument.
|
159 |
|
|
if (is_array($data)) {
|
160 |
|
|
$data['foo'] .= ' theme';
|
161 |
|
|
}
|
162 |
|
|
elseif (is_object($data)) {
|
163 |
|
|
$data->foo .= ' theme';
|
164 |
|
|
}
|
165 |
|
|
// Alter second argument, if present.
|
166 |
|
|
if (isset($arg2)) {
|
167 |
|
|
if (is_array($arg2)) {
|
168 |
|
|
$arg2['foo'] .= ' theme';
|
169 |
|
|
}
|
170 |
|
|
elseif (is_object($arg2)) {
|
171 |
|
|
$arg2->foo .= ' theme';
|
172 |
|
|
}
|
173 |
|
|
}
|
174 |
|
|
// Try to alter third argument, if present.
|
175 |
|
|
if (isset($arg3)) {
|
176 |
|
|
if (is_array($arg3)) {
|
177 |
|
|
$arg3['foo'] .= ' theme';
|
178 |
|
|
}
|
179 |
|
|
elseif (is_object($arg3)) {
|
180 |
|
|
$arg3->foo .= ' theme';
|
181 |
|
|
}
|
182 |
|
|
}
|
183 |
|
|
}
|
184 |
|
|
|
185 |
|
|
/**
|
186 |
|
|
* Implements hook_TYPE_alter() on behalf of block module.
|
187 |
|
|
*
|
188 |
|
|
* This is for verifying that drupal_alter(array(TYPE1, TYPE2), ...) allows
|
189 |
|
|
* hook_module_implements_alter() to affect the order in which module
|
190 |
|
|
* implementations are executed.
|
191 |
|
|
*/
|
192 |
|
|
function block_drupal_alter_foo_alter(&$data, &$arg2 = NULL, &$arg3 = NULL) {
|
193 |
|
|
$data['foo'] .= ' block';
|
194 |
|
|
}
|
195 |
|
|
|
196 |
|
|
/**
|
197 |
|
|
* Implements hook_module_implements_alter().
|
198 |
|
|
*
|
199 |
|
|
* @see block_drupal_alter_foo_alter()
|
200 |
|
|
*/
|
201 |
|
|
function common_test_module_implements_alter(&$implementations, $hook) {
|
202 |
|
|
// For drupal_alter(array('drupal_alter', 'drupal_alter_foo'), ...), make the
|
203 |
|
|
// block module implementations run after all the other modules. Note that
|
204 |
|
|
// when drupal_alter() is called with an array of types, the first type is
|
205 |
|
|
// considered primary and controls the module order.
|
206 |
|
|
if ($hook == 'drupal_alter_alter' && isset($implementations['block'])) {
|
207 |
|
|
$group = $implementations['block'];
|
208 |
|
|
unset($implementations['block']);
|
209 |
|
|
$implementations['block'] = $group;
|
210 |
|
|
}
|
211 |
|
|
}
|
212 |
|
|
|
213 |
|
|
/**
|
214 |
|
|
* Implements hook_theme().
|
215 |
|
|
*/
|
216 |
|
|
function common_test_theme() {
|
217 |
|
|
return array(
|
218 |
|
|
'common_test_foo' => array(
|
219 |
|
|
'variables' => array('foo' => 'foo', 'bar' => 'bar'),
|
220 |
|
|
),
|
221 |
|
|
);
|
222 |
|
|
}
|
223 |
|
|
|
224 |
|
|
/**
|
225 |
|
|
* Theme function for testing drupal_render() theming.
|
226 |
|
|
*/
|
227 |
|
|
function theme_common_test_foo($variables) {
|
228 |
|
|
return $variables['foo'] . $variables['bar'];
|
229 |
|
|
}
|
230 |
|
|
|
231 |
|
|
/**
|
232 |
|
|
* Implements hook_library_alter().
|
233 |
|
|
*/
|
234 |
|
|
function common_test_library_alter(&$libraries, $module) {
|
235 |
|
|
if ($module == 'system' && isset($libraries['farbtastic'])) {
|
236 |
|
|
// Change the title of Farbtastic to "Farbtastic: Altered Library".
|
237 |
|
|
$libraries['farbtastic']['title'] = 'Farbtastic: Altered Library';
|
238 |
|
|
// Make Farbtastic depend on jQuery Form to test library dependencies.
|
239 |
|
|
$libraries['farbtastic']['dependencies'][] = array('system', 'form');
|
240 |
|
|
}
|
241 |
|
|
}
|
242 |
|
|
|
243 |
|
|
/**
|
244 |
|
|
* Implements hook_library().
|
245 |
|
|
*
|
246 |
|
|
* Adds Farbtastic in a different version.
|
247 |
|
|
*/
|
248 |
|
|
function common_test_library() {
|
249 |
|
|
$libraries['farbtastic'] = array(
|
250 |
|
|
'title' => 'Custom Farbtastic Library',
|
251 |
|
|
'website' => 'http://code.google.com/p/farbtastic/',
|
252 |
|
|
'version' => '5.3',
|
253 |
|
|
'js' => array(
|
254 |
|
|
'misc/farbtastic/farbtastic.js' => array(),
|
255 |
|
|
),
|
256 |
|
|
'css' => array(
|
257 |
|
|
'misc/farbtastic/farbtastic.css' => array(),
|
258 |
|
|
),
|
259 |
|
|
);
|
260 |
|
|
return $libraries;
|
261 |
|
|
}
|
262 |
|
|
|
263 |
|
|
/**
|
264 |
|
|
* Adds a JavaScript file and a CSS file with a query string appended.
|
265 |
|
|
*/
|
266 |
|
|
function common_test_js_and_css_querystring() {
|
267 |
|
|
drupal_add_js(drupal_get_path('module', 'node') . '/node.js');
|
268 |
|
|
drupal_add_css(drupal_get_path('module', 'node') . '/node.css');
|
269 |
|
|
// A relative URI may have a query string.
|
270 |
|
|
drupal_add_css('/' . drupal_get_path('module', 'node') . '/node-fake.css?arg1=value1&arg2=value2');
|
271 |
|
|
return '';
|
272 |
|
|
}
|
273 |
|
|
|
274 |
|
|
/**
|
275 |
|
|
* Implements hook_cron().
|
276 |
|
|
*
|
277 |
|
|
* System module should handle if a module does not catch an exception and keep
|
278 |
|
|
* cron going.
|
279 |
|
|
*
|
280 |
|
|
* @see common_test_cron_helper()
|
281 |
|
|
*
|
282 |
|
|
*/
|
283 |
|
|
function common_test_cron() {
|
284 |
|
|
throw new Exception(t('Uncaught exception'));
|
285 |
|
|
} |