Problem/Motivation

Using Facet API Pretty Paths, the facet option "Limit to one active item" is no more working when checked.

Even if checked, multiple values can be selected (links, checkboxes, radios).

Proposed resolution

The sustainable way to fix this problem I found, was to add Facet API Pretty Paths support to the FacetapiWidgetLinks class, which is extended by other plugins as far as I saw (checkboxes, radios).

Remaining tasks

Maybe there is a way for doing this properly by hacking the processor or adaptor of Facet API Pretty Paths.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cancel.allow’s picture

Same problem. When unchecked pretty path in config - limit to one item start working.

cancel.allow’s picture

Tested patch by Johann Wagner. Everything works. Thank you!

seworthi’s picture

Patch does not work if you enable "Make paths unique by sorting them" for said facet in the options for FacetAPI Pretty Paths. Patch assume item to remove is first, which it might not be if sorting enabled. I modified patch to look additional field_alias path not matching the one processing. (changed regex and count($matches[0]) > to >=)

if (module_exists('facetapi_pretty_paths') && !empty($field_alias)) {
    
  // Removes first occurence of filter in path.
  $field_alias_pattern = '#/'.$field_alias.'/[^/]*#';
  if(preg_match_all($field_alias_pattern, $item['#path'], $matches) ){
    if(!empty($matches[0]) && count($matches[0]) > 1){
     $item['#path'] = preg_replace($field_alias_pattern, '', $item['#path'], 1);
   }

Should be:

if (module_exists('facetapi_pretty_paths') && !empty($field_alias)) {
  // Removes additional occurence's of same filter in path.
  $field_alias_pattern = '#/'.$field_alias.'/[^' . $item['#indexed_value'] . ']#';
  if (preg_match_all($field_alias_pattern, $item['#path'], $matches) ) {
    if (!empty($matches[0]) && count($matches[0]) >= 1) {
      $item['#path'] = preg_replace($field_alias_pattern, '', $item['#path'], 1);
   }
Martijn Houtman’s picture

I can confirm that it does not work well with "Make paths unique by sorting them" enabled.I had to use the following regexp, as the regexp from #3 only matches the first character of the value.

  $field_alias_pattern = '#/'.$field_alias.'/(?!' . $item['#indexed_value'] . ')[a-zA-Z0-9-_]+#';
kenorb’s picture

Status: Active » Needs review
steinmb’s picture

Version: 7.x-1.5 » 7.x-1.x-dev

Status: Needs review » Needs work

The last submitted patch, facetapi_pretty_paths_limit_active_items.patch, failed testing.