1 common.inc backdrop_get_query_parameters(array $query = NULL, array $exclude = array('q'), $parent = '')

Processes 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().:

Related topics

File

core/includes/common.inc, line 497
Common functions that many Backdrop modules will need to reference.

Code

function backdrop_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] = backdrop_get_query_parameters($value, $exclude, $string_key);
    }
    else {
      $params[$key] = $value;
    }
  }

  return $params;
}