This repository has been archived by the owner on Oct 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
core-menu_links_with_query_param-1220410-#16.patch
167 lines (161 loc) · 7.24 KB
/
core-menu_links_with_query_param-1220410-#16.patch
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
diff --git a/includes/common.inc b/includes/common.inc
index 20cc82b..b68b2f5 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -450,16 +450,21 @@ function drupal_get_query_parameters(array $query = NULL, array $exclude = array
*
* @param $query
* The query string to split.
+ * @param $decode
+ * Defaults to TRUE. Boolean flag indicating that the return value should be
+ * URL-decoded.
*
* @return
* An array of URL decoded couples $param_name => $value.
*/
-function drupal_get_query_array($query) {
+function drupal_get_query_array($query, $decode = TRUE) {
$result = array();
if (!empty($query)) {
foreach (explode('&', $query) as $param) {
$param = explode('=', $param, 2);
- $result[$param[0]] = isset($param[1]) ? rawurldecode($param[1]) : '';
+ $key = ($decode) ? rawurldecode($param[0]) : $param[0];
+ $value = isset($param[1]) ? ($decode) ? rawurldecode($param[1]) : $param[1] : '';
+ $result[$key] = $value;
}
}
return $result;
@@ -473,6 +478,9 @@ function drupal_get_query_array($query) {
*
* @param $query
* The query parameter array to be processed, e.g. $_GET.
+ * @param $encode
+ * Defaults to TRUE. Boolean flag indicating that the return value should be
+ * URL-encoded.
* @param $parent
* Internal use only. Used to build the $query array key for nested items.
*
@@ -483,15 +491,16 @@ function drupal_get_query_array($query) {
* @see drupal_get_query_parameters()
* @ingroup php_wrappers
*/
-function drupal_http_build_query(array $query, $parent = '') {
+function drupal_http_build_query(array $query, $encode = TRUE, $parent = '') {
$params = array();
foreach ($query as $key => $value) {
- $key = ($parent ? $parent . '[' . rawurlencode($key) . ']' : rawurlencode($key));
+ $raw_key = ($encode) ? rawurlencode($key) : $key;
+ $key = ($parent ? $parent . '[' . $raw_key . ']' : $raw_key);
// Recurse into children.
if (is_array($value)) {
- $params[] = drupal_http_build_query($value, $key);
+ $params[] = drupal_http_build_query($value, $encode, $key);
}
// If a query parameter value is NULL, only append its key.
elseif (!isset($value)) {
@@ -499,7 +508,8 @@ function drupal_http_build_query(array $query, $parent = '') {
}
else {
// For better readability of paths in query strings, we decode slashes.
- $params[] = $key . '=' . str_replace('%2F', '/', rawurlencode($value));
+ $raw_value = ($encode) ? rawurlencode($value) : $value;
+ $params[] = $key . '=' . str_replace('%2F', '/', $raw_value);
}
}
@@ -2168,6 +2178,8 @@ function format_username($account) {
* elements:
* - 'query': An array of query key/value-pairs (without any URL-encoding) to
* append to the URL.
+ * - 'encode': Defaults to TRUE. Boolean flag indicating that the return value
+ * of query parameters should be URL-encoded.
* - 'fragment': A fragment identifier (named anchor) to append to the URL.
* Do not include the leading '#' character.
* - 'absolute': Defaults to FALSE. Whether to force the output to be an
@@ -2211,7 +2223,8 @@ function url($path = NULL, array $options = array()) {
'query' => array(),
'absolute' => FALSE,
'alias' => FALSE,
- 'prefix' => ''
+ 'prefix' => '',
+ 'encode' => TRUE,
);
if (!isset($options['external'])) {
@@ -2245,7 +2258,7 @@ function url($path = NULL, array $options = array()) {
}
// Append the query.
if ($options['query']) {
- $path .= (strpos($path, '?') !== FALSE ? '&' : '?') . drupal_http_build_query($options['query']);
+ $path .= (strpos($path, '?') !== FALSE ? '&' : '?') . drupal_http_build_query($options['query'], $options['encode']);
}
if (isset($options['https']) && variable_get('https', FALSE)) {
if ($options['https'] === TRUE) {
@@ -2297,7 +2310,7 @@ function url($path = NULL, array $options = array()) {
if (!empty($GLOBALS['conf']['clean_url'])) {
$path = drupal_encode_path($prefix . $path);
if ($options['query']) {
- return $base . $path . '?' . drupal_http_build_query($options['query']) . $options['fragment'];
+ return $base . $path . '?' . drupal_http_build_query($options['query'], $options['encode']) . $options['fragment'];
}
else {
return $base . $path . $options['fragment'];
diff --git a/includes/menu.inc b/includes/menu.inc
index 2bfa39f..3786cc0 100644
--- a/includes/menu.inc
+++ b/includes/menu.inc
@@ -1626,6 +1626,11 @@ function theme_menu_link(array $variables) {
$element = $variables['element'];
$sub_menu = '';
+ // Set the encode option to FALSE for query parameter so query parameters
+ // does not encode.
+ if (isset($element['#localized_options']['query'])) {
+ $element['#localized_options']['encode'] = FALSE;
+ }
if ($element['#below']) {
$sub_menu = drupal_render($element['#below']);
}
@@ -1865,6 +1870,11 @@ function menu_navigation_links($menu_name, $level = 0) {
$class = ' active-trail';
$l['attributes']['class'][] = 'active-trail';
}
+ // If query parameter available set the encode option to FALSE for query
+ // parameter so query parameters does not encode.
+ if (!empty($item['link']['options']) && isset($item['link']['options']['query'])) {
+ $l['encode'] = FALSE;
+ }
// Normally, l() compares the href of every link with $_GET['q'] and sets
// the active class accordingly. But local tasks do not appear in menu
// trees, so if the current path is a local task, and this link is its
diff --git a/modules/menu/menu.admin.inc b/modules/menu/menu.admin.inc
index 66bd6f3..8e2d6ce 100644
--- a/modules/menu/menu.admin.inc
+++ b/modules/menu/menu.admin.inc
@@ -99,6 +99,11 @@ function _menu_overview_tree_form($tree) {
$mlid = 'mlid:' . $item['mlid'];
$form[$mlid]['#item'] = $item;
$form[$mlid]['#attributes'] = $item['hidden'] ? array('class' => array('menu-disabled')) : array('class' => array('menu-enabled'));
+ // Set the encode option to FALSE for query parameter so query parameters
+ // does not encode.
+ if (isset($item['localized_options']['query'])) {
+ $item['localized_options']['encode'] = FALSE;
+ }
$form[$mlid]['title']['#markup'] = l($item['title'], $item['href'], $item['localized_options']);
if ($item['hidden']) {
$form[$mlid]['title']['#markup'] .= ' (' . t('disabled') . ')';
@@ -294,7 +299,7 @@ function menu_edit_item($form, &$form_state, $type, $item, $menu) {
$path = $item['link_path'];
if (isset($item['options']['query'])) {
- $path .= '?' . drupal_http_build_query($item['options']['query']);
+ $path .= '?' . drupal_http_build_query($item['options']['query'], FALSE);
}
if (isset($item['options']['fragment'])) {
$path .= '#' . $item['options']['fragment'];
@@ -382,7 +387,7 @@ function menu_edit_item_validate($form, &$form_state) {
if (!url_is_external($item['link_path'])) {
$parsed_link = parse_url($item['link_path']);
if (isset($parsed_link['query'])) {
- $item['options']['query'] = drupal_get_query_array($parsed_link['query']);
+ $item['options']['query'] = drupal_get_query_array($parsed_link['query'], FALSE);
}
else {
// Use unset() rather than setting to empty string