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
Comment | File | Size | Author |
---|---|---|---|
#45 | url_duplication-3254600-45.patch | 1.16 KB | guy_schneerson |
| |||
#43 | url_duplication-3254600-43.patch | 1.06 KB | guy_schneerson |
#30 | 3254600-30.patch | 1.13 KB | StryKaizer |
#13 | url-duplication.patch | 1.06 KB | Jl6owa |
Comments
Comment #2
sagesolutions CreditAttribution: sagesolutions commentedAfter 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 ofresults
since my page view is at /results.Below is a patch that needs testing.
Comment #3
sagesolutions CreditAttribution: sagesolutions commentedComment #5
Maschenmode CreditAttribution: Maschenmode as a volunteer commentedI had the same problem here, the Patch works for me on Drupal 9.3.0, php 8.0.
Comment #6
Qusai Taha CreditAttribution: Qusai Taha at Vardot commentedPatch #3 works fine for me on Drupal 9.3.0, thank you
Comment #7
Ahmad Abbad CreditAttribution: Ahmad Abbad as a volunteer and at Vardot for Vardot commentedPatch #3 works for me on Drupal 9.3.0 and facets 2.0.0
Comment #8
Ahmad Abbad CreditAttribution: Ahmad Abbad as a volunteer and at Vardot for Vardot commentedComment #9
StryKaizerThx 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.
Comment #10
StryKaizerFix attached which should work for all routes.
Comment #11
Johan den Hollander CreditAttribution: Johan den Hollander commentedTested 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.
Comment #12
StryKaizer@johan can you describe why 10 did not work for you?
Comment #13
Jl6owa CreditAttribution: Jl6owa commentedPatch 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
Comment #14
retrodans CreditAttribution: retrodans at Agile Collective commentedI 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.
Comment #15
retrodans CreditAttribution: retrodans at Agile Collective commentedNot 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.
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
Comment #16
devad CreditAttribution: devad as a volunteer commentedThe 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.Comment #17
proweb.ua CreditAttribution: proweb.ua commentedI was wrong, was chosen: Short pretty paths
If Pretty paths is selected then it works
Comment #18
Johan den Hollander CreditAttribution: Johan den Hollander commentedJust 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.
Comment #19
KarimB CreditAttribution: KarimB as a volunteer and commentedThe 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.
Comment #20
marcoka CreditAttribution: marcoka commentedI 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.
Comment #21
Johan den Hollander CreditAttribution: Johan den Hollander at Finalist commented@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.
Comment #22
vradova CreditAttribution: vradova commentedHi!
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!
Comment #23
gsquirrelI 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.
Comment #24
WiseMike CreditAttribution: WiseMike commentedI have applied patch #13 and it fixed issue https://www.drupal.org/project/facets/issues/3268360
Comment #25
ckngPatch #13 works for us, it fixes the filter and url, and fixes facet summary #3268360: Incompatibilities between facets_pretty_paths and facets 2.0.
Comment #26
MeenakshiG CreditAttribution: MeenakshiG at Srijan | A Material+ Company for Drupal India Association commentedWas facing an issue in URL formation in a path-based multisite configuration.
Updated the patch for the same.
Comment #27
marcoka CreditAttribution: marcoka commented#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
Comment #28
Johan den Hollander CreditAttribution: Johan den Hollander at Finalist commentedWe 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.
Comment #29
Denes.Szabo CreditAttribution: Denes.Szabo as a volunteer commentedThe patch from the #13 seems ok, but the #25 doesn't.
I added the patch for the facets from the #3268360 also.
Comment #30
StryKaizerI adjusted patch 13 so it also supports routes with parameters (e.g. when facets are rendered on a node page).
Comment #31
FMB CreditAttribution: FMB commentedThanks for you work. Patch #13 fixes the reset URL ((-) link), patch #30 doesn't.
Comment #32
proweb.ua CreditAttribution: proweb.ua commented#30 not work
Comment #33
proweb.ua CreditAttribution: proweb.ua commentedAfter patch #13 there was such a bug Some mandatory parameters are missing
Comment #34
fabianderijkPatch #13 works for me, patch #30 doesn't.
I haven't encountered the issues as mentioned in #3293972: Some mandatory parameters are missing
Comment #35
marcoka CreditAttribution: marcoka commentedI 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
Comment #36
Volker23 CreditAttribution: Volker23 commentedI have tried the patch combination from #35 but without success, instead #13 helped to fix my case.
Comment #37
minorOffense CreditAttribution: minorOffense at Coldfront Labs Inc. commentedThe described setup in #35 worked for us.
Comment #38
Glugmeister CreditAttribution: Glugmeister commented#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
Comment #39
init90For 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.)
Comment #40
proweb.ua CreditAttribution: proweb.ua commented#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
Comment #41
marcoka CreditAttribution: marcoka commentedWith 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
Comment #42
ScorpionGhost CreditAttribution: ScorpionGhost commenteddoesn't work either
Comment #43
guy_schneerson CreditAttribution: guy_schneerson commentedNone 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.
Comment #45
guy_schneerson CreditAttribution: guy_schneerson commentedThe previous patch doubled up the leading slash. This patch fixes it.
Comment #46
nno CreditAttribution: nno commented#45 works great. Thank you very much!
Comment #47
joseph.olstadPatch 45 works great on 1.4.0
Great work and is desperately needed!
Comment #48
joseph.olstadComment #49
hongqing CreditAttribution: hongqing commentedPatch 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.
Comment #50
ifrikUsing 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
Comment #51
fallenturtle CreditAttribution: fallenturtle commentedI'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.
Comment #52
krug CreditAttribution: krug as a volunteer commentedDrupal 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!
Comment #54
joseph.olstadComment #55
marcoka CreditAttribution: marcoka commentedThank 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