function bef_replace_query_string_arg in Better Exposed Filters 7.3
Same name and namespace in other branches
- 8.3 better_exposed_filters.theme \bef_replace_query_string_arg()
- 6.3 better_exposed_filters.theme \bef_replace_query_string_arg()
- 6 better_exposed_filters.theme \bef_replace_query_string_arg()
- 6.2 better_exposed_filters.theme \bef_replace_query_string_arg()
- 7 better_exposed_filters.theme \bef_replace_query_string_arg()
Replaces/adds a given query string argument to the current URL.
Parameters
string $key: Query string key (argument).
string $value: Query string value.
bool $multiple: (optional) TRUE if this key/value pair allows multiple values.
bool $remove: (optional) TRUE if this key/value should be a link to remove/unset the filter.
string $path: (optional) Use this specify the View results page when the exposed form is displayed as a block and may be a different URL from the results. Defaults to the current path if unspecified.
Return value
string URL.
1 call to bef_replace_query_string_arg()
- theme_select_as_links in ./
better_exposed_filters.theme - Themes a select drop-down as a collection of links.
File
- ./
better_exposed_filters.theme, line 732 - Provides theming functions to display exposed forms using different interfaces.
Code
function bef_replace_query_string_arg($key, $value, $multiple = FALSE, $remove = FALSE, $path = '') {
if (!$path) {
$path = implode('/', arg());
}
// Prevents us from having to check for each index from parse_url that we may
// use.
$urllist = array(
'path' => '',
'fragment' => '',
'query' => '',
);
$urllist = array_merge($urllist, parse_url(request_uri()));
$fragment = urldecode($urllist['fragment']);
$query = array();
parse_str($urllist['query'], $query);
if (isset($query[$key]) && is_array($query[$key])) {
// Multiple values allowed for this existing key.
if ($remove && ($key_remove = array_search($value, $query[$key])) !== FALSE) {
unset($query[$key][$key_remove]);
}
else {
$query[$key][] = $value;
}
}
else {
// Create a new key.
if ($multiple && !$remove) {
$query[$key] = array(
$value,
);
}
elseif (!$remove) {
$query[$key] = $value;
}
}
// Unset page arg so we don't land on an empty page off the end of the newly
// filtered listing.
unset($query['page']);
return url(ltrim($path, '/'), array(
'query' => $query,
'fragment' => $fragment,
'absolute' => TRUE,
));
}