drupal_get_query_parameters

Versions
7
drupal_get_query_parameters(array $query = NULL, array $exclude = array('q'), $parent = '')

Process a URL query parameter array to remove unwanted elements.

Parameters

$query (optional) An array to be processed. Defaults to $_GET.

$exclude (optional) A list of $query array keys to remove. Use "parent[child]" to exclude nested items. Defaults to array('q').

$parent Internal use only. Used to build the $query array key for nested items.

Return value

An array containing query parameters, which can be used for url().

▾ 6 functions call drupal_get_query_parameters()

drupal_get_destination in includes/common.inc
Prepare a 'destination' URL query parameter for use in combination with drupal_goto().
drupal_get_query_parameters in includes/common.inc
Process a URL query parameter array to remove unwanted elements.
pager_get_query_parameters in includes/pager.inc
Compose a URL query parameter array for pager links.
shortcut_page_build in modules/shortcut/shortcut.module
Implement hook_page_build().
tablesort_get_query_parameters in includes/tablesort.inc
Compose a URL query parameter array for table sorting links.
theme_pager_link in includes/pager.inc
Format a link to a specific query result page.

Code

includes/common.inc, line 418

<?php
function drupal_get_query_parameters(array $query = NULL, array $exclude = array('q'), $parent = '') {
  // Set defaults, if none given.
  if (!isset($query)) {
    $query = $_GET;
  }
  // If $exclude is empty, there is nothing to filter.
  if (empty($exclude)) {
    return $query;
  }
  elseif (!$parent) {
    $exclude = array_flip($exclude);
  }

  $params = array();
  foreach ($query as $key => $value) {
    $string_key = ($parent ? $parent . '[' . $key . ']' : $key);
    if (isset($exclude[$string_key])) {
      continue;
    }

    if (is_array($value)) {
      $params[$key] = drupal_get_query_parameters($value, $exclude, $string_key);
    }
    else {
      $params[$key] = $value;
    }
  }

  return $params;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.