You are here

function ajax_facets_facet_build_reset_path in Ajax facets 7

Same name and namespace in other branches
  1. 7.3 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.

3 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().
FacetapiAjaxWidgetSelect::buildListItems in plugins/facetapi/ajax_widget_select.inc
Transforms the render array for use with theme_item_list().

File

./ajax_facets.module, line 108
Ajax facets implementation.

Code

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

  // Build query params except current facet filters.
  foreach ($params[$filter_key] as $param) {
    if (strpos($param, $facet['name']) !== 0) {
      $clean_params[] = $param;
    }
  }
  $url_params = array();
  if (!empty($clean_params)) {
    $url_params = array(
      'query' => array(
        $filter_key => $clean_params,
      ),
    );
  }
  $unset_keys = array(
    '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);
}