Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
My website had a redesign some time ago. In this redesign, some facet machine names were changed.
My problem is that search engine bots have indexed urls with the old names such as:
/my/page?f[0]=foobar
When no facet with this name is found, I get a 500 response with this error.
Uncaught PHP Exception InvalidArgumentException: "The Facet could not be loaded." at /mnt/www/html/dkrweb/docroot/modules/contrib/facets/src/Utility/FacetsUrlGenerator.php
What I want to achieve is that, if a facet with the non-valid name is supplied on the query string, that this is ignored.
Proposed resolution
The solution I came up with is in the attached patch, which I apply against version 8.x-1.1. It works for me, because I have a RangeSlider on my page, I'm not sure if it will work for everyone.
Comment | File | Size | Author |
---|---|---|---|
#2 | 3012047-2.patch | 837 bytes | michaellenahan |
Comments
Comment #2
michaellenahan CreditAttribution: michaellenahan at Hubert Burda Media commentedHere's the patch, it simply removes invalid items from the
$active_filters
array in\Drupal\facets_range_widget\Plugin\facets\processor\RangeSliderProcessor::build
Comment #3
vdenis CreditAttribution: vdenis at Agiledrop - Your Trusted Drupal Teammates commentedComment #5
borisson_Yep, looks very solid and really simple. Committed and pushed, thanks!