You are here

function ajax_facets_facet_build_reset_path in Ajax facets 7.3

Same name and namespace in other branches
  1. 7 ajax_facets.module \ajax_facets_facet_build_reset_path()
  2. 7.2 ajax_facets.module \ajax_facets_facet_build_reset_path()

Return Drupal formed url for reset current facet filter.

4 calls to ajax_facets_facet_build_reset_path()
ajax_facets_process_facet_blocks in ./ajax_facets.module
Generates an array of facet block data for a given searcher and realm
FacetapiAjaxWidgetCheckboxes::buildListItems in plugins/facetapi/ajax_widget_checkboxes.inc
Transforms the render array for use with theme_item_list().
FacetapiAjaxWidgetRanges::buildListItems in plugins/facetapi/ajax_widget_ranges.inc
Transforms the render array for use with theme_item_list().
FacetapiAjaxWidgetSelect::buildListItems in plugins/facetapi/ajax_widget_select.inc
Transforms the render array for use with theme_item_list().

File

./ajax_facets.module, line 170

Code

function ajax_facets_facet_build_reset_path($facet, $adapter) {
  $params = $adapter
    ->getUrlProcessor()
    ->fetchParams();
  $filter_key = $adapter
    ->getUrlProcessor()
    ->getFilterKey();
  $clean_params = [];
  $url_params = [];

  // Build query params except current facet filters.
  if (!empty($params[$filter_key])) {
    foreach ($params[$filter_key] as $param) {
      if (strpos($param, $facet['name']) !== 0) {
        $clean_params[] = $param;
      }
    }
    $url_params = [];
    if (!empty($clean_params)) {
      $url_params = [
        'query' => [
          $filter_key => $clean_params,
        ],
      ];
    }
    $unset_keys = [
      'searchPath',
      'q',
      'page',
      $filter_key,
    ];

    // Remove default params from redirect.
    foreach ($params as $key => $value) {
      if (!in_array($key, $unset_keys)) {
        $url_params['query'][$key] = $value;
      }
    }
  }
  return url(!empty($_GET['searchPath']) ? $_GET['searchPath'] : $adapter
    ->getSearchPath(), $url_params);
}