W3cubDocs

/Drupal 8

public static function UrlHelper::filterQueryParameters

public static UrlHelper::filterQueryParameters(array $query, array $exclude = array(), $parent = '')

Filters a URL query parameter array to remove unwanted elements.

Parameters

array $query: An array to be processed.

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

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

Return value

An array containing query parameters.

File

core/lib/Drupal/Component/Utility/UrlHelper.php, line 82

Class

UrlHelper
Helper class URL based methods.

Namespace

Drupal\Component\Utility

Code

public static function filterQueryParameters(array $query, array $exclude = array(), $parent = '') {
  // 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] = static::filterQueryParameters($value, $exclude, $string_key);
    }
    else {
      $params[$key] = $value;
    }
  }

  return $params;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Component!Utility!UrlHelper.php/function/UrlHelper::filterQueryParameters/8.1.x