Problem/Motivation

Upgraded to Drupal 9, Facets 2.0.0, and facet pretty paths 8.x-1.2

When pretty paths are enabled, the urls have extra/duplicate filters shown.

Also I cannot uncheck a filter when clicking on the (-) next to the selected filter. The link is going to the facet itself instead of the parent facet.

When using multiple filters, the filters appear across both, creating duplicate filters in the url. For example Filtering by toys and then location, my url shows the toys category multiple times. /results/c/toys-1/c/toys-1/l/alberta-123

Changing my facet settings url processor back to query string allows the facet filtering to work correctly

Steps to reproduce

  • upgrade to Drupal 9, Facets 2.0.0 and use Facets Pretty Paths 8.x-1.2
  • Create a facet (I used a taxonomy term facet)
  • Filter on an item
  • Try to un-filter on same item

Proposed resolution

Fix how pretty paths is converting facet params into urls

Remaining tasks

fix url processing

User interface changes

None

API changes

None

Data model changes

None

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sagesolutions created an issue. See original summary.

sagesolutions’s picture

Status: Active » Needs review
FileSize
4.69 KB

After some debugging, i think I have a fix for it. $facet->getFacetSource()->getPath() is returning the full url, not the main url.

For example, it was retuning results/c/toys-1 instead of results since my page view is at /results.

Below is a patch that needs testing.

sagesolutions’s picture

Maschenmode’s picture

I had the same problem here, the Patch works for me on Drupal 9.3.0, php 8.0.

Qusai Taha’s picture

Patch #3 works fine for me on Drupal 9.3.0, thank you

Ahmad Abbad’s picture

Patch #3 works for me on Drupal 9.3.0 and facets 2.0.0

Ahmad Abbad’s picture

Status: Needs review » Reviewed & tested by the community
StryKaizer’s picture

Status: Reviewed & tested by the community » Needs work

Thx for contributing!

patch from #3 only works if the current route does not expect parameters.
You need to use the facetsource->getPath() function instead.

Also, please only include actual changes in your patch, it took a while to see what you actually changed as there is debug and linebreaks in your patch.

StryKaizer’s picture

Status: Needs work » Needs review
FileSize
1.01 KB

Fix attached which should work for all routes.

Johan den Hollander’s picture

Tested patches 3 and 10.
#3 worked best in resetting individual facets and preventing duplicates in the url but the reset all facets link did not work.

Downgrading Facets module to 1.8 works best at the moment.

StryKaizer’s picture

@johan can you describe why 10 did not work for you?

Jl6owa’s picture

Patch from #10 was not working for me too, as Url::fromUri('internal:' . $facet->getFacetSource()->getPath()); was returning full path, including selected facets which led to query duplication.
So I kinda combined both versions to one and got this

retrodans’s picture

I was just about to comment on this myself. @Jl6owa unfiltering appears to work using your patch, but sadly the 'reset' button doesn't remove all filters still. I will have a look myself to see if I can find out why, but wanted to share the update after my quick test.

retrodans’s picture

Not sure if the reset issue is related to this or not, but basically if I go into ResetFacetsProcessor.php and add the below lines just after the query gets set, it "fixes" it.

$routeParams = $url->getRouteParameters();
    $routeParams['facets_query'] = "";
    $url->setRouteParameters($routeParams);

Would be good to get someones thoughts on this though before I create a patch, as it feels like I would be patching facets for something caused by facets_pretty_paths

devad’s picture

Status: Needs review » Needs work

The patch #13 works for me.

But if I have the url alias set on my main search page for example like this:

/search -> /search-all

then it does not work any more. Because the patch #13 keeps the alias base url at all future search pages and paths like /search-all/category/12 result with "The requested page could not be found." errors. The alias is set to work for the main search page only and should be ignored at other filtered pages.

proweb.ua’s picture

#13 not work

I can't uncheck the checkbox.
And after each click, the url is added

/catalog/category/10
/catalog/category/10/category/10.16
/catalog/category/10/category/10.16/category/10.16
/catalog/category/10/category/10.16/category/10.16/category/10.10.10.16

I was wrong, was chosen: Short pretty paths

If Pretty paths is selected then it works

Johan den Hollander’s picture

Status: Needs work » Needs review

Just did a test with the #13 patch.
It works well for me as I can reset individual facets and also use the Reset all facets link.

Tested with Facets: 2.0.1 and Facets Pretty Paths: 8.x-1.2.

KarimB’s picture

The patch #13 works for me with
- Drupal 9.3.3
- facets 2.0.1
- facets_pretty_paths 8.x-1.2
But... the "Clear all" from the facet_summary is not working.

marcoka’s picture

I started testing #13, works here.
Without it the click on an active facet (remove) does not work at all because it links to itself, same path. With the patch this problem is solved.
As i am building a views page with facets currently i will test this more.

Reset, does not work. I will test what was suggested in a comment above.
Edit: Ok its a patch for facets. Should that be discussed in the facets api?

What also works is changing the buttons link in the template manually.

@retrodans, thank you that also works here.

Johan den Hollander’s picture

@retrodans is right and I did not test with facets_summary before. Just the regular reset facets link (without the summary).

I added a related issue. Some started this in the Facets issues.

vradova’s picture

Hi!

I can confirm that patch #13 fixed my issue.

Also, I create an Issue Johan named in his post -> https://www.drupal.org/project/facets/issues/3268360

Thanks!

gsquirrel’s picture

I have used this patch on two sites now to solve very similar issues with facets after upgrading to drupal 9. Has worked well on both sites.

WiseMike’s picture

I have applied patch #13 and it fixed issue https://www.drupal.org/project/facets/issues/3268360

ckng’s picture

Patch #13 works for us, it fixes the filter and url, and fixes facet summary #3268360: Incompatibilities between facets_pretty_paths and facets 2.0.

MeenakshiG’s picture

Was facing an issue in URL formation in a path-based multisite configuration.
Updated the patch for the same.

marcoka’s picture

#13 or #26 do no tseem to work with tha latest
- facets: 2.0.2 Stable release covered by the Drupal Security Team released 4 April 2022

The reset link is not the views path (/test) it is the facet query path like /test/type/red

Its a bit unclear to me. Using tha patch from the facets queue in combination works.

#3268360: Incompatibilities between facets_pretty_paths and facets 2.0 comment-14438338

Johan den Hollander’s picture

We are still using the #13 patch in combination with the #3268360 patch for Facets module and this works well.

I just tested the #26 patch by MeenakshiG in combination with the #3268360 and this gives the same results as what this issue was started for. Not being able to reset the induvidual facets via the facets summary. The reset all facets link does work.

Denes.Szabo’s picture

The patch from the #13 seems ok, but the #25 doesn't.

I added the patch for the facets from the #3268360 also.

StryKaizer’s picture

I adjusted patch 13 so it also supports routes with parameters (e.g. when facets are rendered on a node page).

FMB’s picture

Thanks for you work. Patch #13 fixes the reset URL ((-) link), patch #30 doesn't.

proweb.ua’s picture

#30 not work

proweb.ua’s picture

After patch #13 there was such a bug Some mandatory parameters are missing

fabianderijk’s picture

Patch #13 works for me, patch #30 doesn't.

I haven't encountered the issues as mentioned in #3293972: Some mandatory parameters are missing

marcoka’s picture

I just checked the problem after some time again using recent patches. Combination of these two worked.

facets_pretty_paths
#3254600: Cannot filter properly when using facet pretty paths
Patch #30 by StryKaizer
https://www.drupal.org/project/facets_pretty_paths/issues/3254600#commen...

facets
#3268360: Incompatibilities between facets_pretty_paths and facets 2.0
Patch #3 by Johan den Hollander
https://www.drupal.org/project/facets/issues/3268360#comment-14438338

Volker23’s picture

I have tried the patch combination from #35 but without success, instead #13 helped to fix my case.

minorOffense’s picture

The described setup in #35 worked for us.

Glugmeister’s picture

#30 does not work for our setup. #13 worked for us in combination with #3 in #3268360: Incompatibilities between facets_pretty_paths and facets 2.0

Tested with:
- drupal 9.4.8
- facets 2.0.5
- facets_pretty_paths 8.x-1.2

init90’s picture

For me, the best results were achieved by a combination of patches from #3293174: The cache_data table grows fast and #3268360: Incompatibilities between facets_pretty_paths and facets 2.0.
Patch #13 also works, but with it still exists a cache problem(in my case about 300GB of cache in a few days.)

proweb.ua’s picture

#39 this is the only solution that worked for me

But at the same time, when applying the filter, the clean url of the page is lost

taxonomy page with clean url (taxonomy/term/12)
https://site.name/hotels

clean url disappears after applying filter
https://site.name/taxonomy/term/12/country/austria

marcoka’s picture

With the latest facets version and drupal 9.5 #35 only works for the reset button.
The remove facet links do not work no more. It just links the url itself.

Using this patch in addition, it works again: https://www.drupal.org/files/issues/2022-01-11/url-duplication.patch

ScorpionGhost’s picture

doesn't work either

guy_schneerson’s picture

None of the patches worked properly for me so I had a good look at the code and while I do not fully understand the ecosystem, the issue looked obvious and easy to solve.
What the code currently does is in buildUrls() is build up $pretty_paths_string. This holds a sorted list of the existing facet URL fragment + the URL fragment of the specific facet value the code is generating the URL for.
It then gets the existing facet URL and appends the two together.
The problem is that getting the path using $facet->getFacetSource()->getPath() also returns the existing facet URL fragment and it gets doubled up.
My solution was to simply replace the URLs facets_query with the $pretty_paths_string that holds a complete and sorted version of the facets_query URL fragment.
Hope that makes sense.

Status: Needs review » Needs work

The last submitted patch, 43: url_duplication-3254600-43.patch, failed testing. View results

guy_schneerson’s picture

Status: Needs work » Needs review
FileSize
1.16 KB

The previous patch doubled up the leading slash. This patch fixes it.

nno’s picture

#45 works great. Thank you very much!

joseph.olstad’s picture

Version: 8.x-1.2 » 8.x-1.4

Patch 45 works great on 1.4.0

Great work and is desperately needed!

joseph.olstad’s picture

Status: Needs review » Reviewed & tested by the community
hongqing’s picture

Patch 45 does not work well with Drupal 10.0.8 with Facets 2.0.6 and Facets Pretty Paths 8.x-1.4. Without this patch, the url/category_a/1/category_b/11 becomes /category_a/1/category_b/11/category_a/1/category_b/12, with this patch, the url becomes category_a/1/category_b/11/category_b/12 but not category_a/1/category_b/11,12 as expected.

------
I am wrong about the function of Facets Pretty Paths. In order to display like category_a/1/category_b/11,12, the module Facets Short Pretty Paths should be used.

ifrik’s picture

Using Facets Pretty Paths 8.1.4 and Facets 2.0.5

Patch #13 works when used together with patch #3 from [3268360]

Patch #45 does not work for me, neither with or without the Facets patch

fallenturtle’s picture

I'm using Pretty Paths 8.x-1.4 and Facets 2.0.6. After patch 45 when I click on a facet it adds it to the url, but the facet itself doesn't get checked.

krug’s picture

Drupal Version 9.5.9
PHP Version 8.1.15
facets 2.0.6
acets_pretty_paths 8.x-1.4

Before the patch. Category multiple times.
test.com/products/aaaaa/525/aaaaa/525/bbbbb/523/aaaaa/525/aaaaa/525/bbbbb/523/ccccc/325/aaaaa/525/aaaaa/525/aaaaa/525/aaaaa/525/bbbbb/523/bbbbb/523/ccccc/325/ddddd/332

Patch #45 works great. Thank you very much!

joseph.olstad’s picture

Status: Reviewed & tested by the community » Fixed
marcoka’s picture

Thank you very much.

Feedback: That also works here with
drupal 10.1
facets 2.0.6
and Facets Short Pretty Paths 1.0.0-alpha4

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.