I have Views with Facets, that placed on page as block via Layouts Builder. And I place block, contains Facet with "List of links" widget, displayed on all site pages, not only in my views page - with unchecked "Hide facet when facet source is not rendered" I can normally display this block on any page.
But the problem is that widget links of this block targets to current page url, instead of my views page url. So, if I visit/about url, facet block contains links like /about?f[0]=param:value (on /about page) instead of /my-views-page?f[0]=param:value.
In Drupal 7.x, regarding to https://www.drupal.org/docs/7/modules/search-api/advanced-site-building-... , I can add "Facets block" Views display, where can I set "Search page path", but this feature is missing in Drupal 8.x branch.
So, how can I set needed URL for widget items links in Facets block?
| Comment | File | Size | Author |
|---|---|---|---|
| #35 | facets-set_base_path-3057943-35.patch | 6.96 KB | damienmo |
| #34 | facets-set_base_path-3057943-34.patch | 6.79 KB | damienmo |
| #33 | facets-set_base_path-3057943-33.patch | 6.49 KB | mistrae |
| #25 | facets-set_base_path-3057943-25.patch | 6.57 KB | atoll |
| #24 | facets-set_base_path-3057943-24.patch | 6.68 KB | cluke009 |
Issue fork facets-3057943
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
murzFacet Views Display mode is removed from D8 version #2604906: Remove Facet Views Display mode so is there any replacement for implement same feature?
Comment #3
murzComment #4
lamp5I think that you can try something like this:Comment #5
lamp5Hmm now I think that we need patch for this....
Comment #7
siavash commentedThis is a great functionality!
After enabling and saving facets I get this when clearing cache:
Error: Uncaught Error: Call to a member function getBasePath() on null in /web/modules/contrib/facets/src/Plugin/facets/facet_source/SearchApiDisplay.php:146
Also base_path field is not set with my value - but field validation was working in terms of verifying valid URL.
Have not done a ton of testing will probably handle it using preprocess but thanks for working on this! Hope to see it get fixed and committed.
Comment #8
lamp5Hi @Siavash. Thanks for your tests. Could you give me steps to reproduce this error? For me, this solution works fine.
Comment #9
ludo.rHello,
Thanks for providing this functionnality, it's really helpful!
However I applied the patch, I can set the base path, I don't have any errors, but the link is still based on the current page and not the base path.
I'm setting it to a specific node:
/node/123Comment #10
lamp5HI @dolu. Please check why
$this->facet->getBasePath()does not return your path in/src/Plugin/facets/facet_source/SearchApiDisplay.php, then we can improve my solution and find way to fix tests.Comment #11
ludo.rHi @lamp5,
It IS returning my configured base path
/node/123(I cleared the cache prior testing using drush cr).But the link still uses the current page path.
Comment #12
lamp5@dolu your view with search api results is page or block?
Comment #13
ludo.rIt is a block.
Here's my configuration with 2 pages:
- Page 1 (/node/456)
-- my_view-block1
-- facet
- Page 2 (/node/123)
-- my_view-block2
-- facet
the facet is linked to my_view-block2
So when being on Page 1, I'd like the facetlinks to point to Page 2.
I can send you the config if needed.
Thanks!
Comment #14
rutiolmaI'm proposing a new patch since I'm getting the same issue as @dolu.
Could this be a solution?
This is a patch for Facets 1.4 and doesn't apply on dev brach.
Comment #15
efpapado commentedThis should apply to the dev.
Comment #16
jwwj commentedI tried applying the patch in #15, and I'm getting the same symptoms as in #7. Did nothing other than add the patch to my composer.json, run composer update, then "drupal cache:rebuild all". And the exception I get is
could be because of the facets_pretty_paths module I also have installed, which maybe clashes with this patch. I tried to uninstall facets_pretty_paths. The cache:rebuild worked after that, but apparently it does not uninstall cleanly as I started to get errors in other parts instead... still trying to debug that part.
Comment #17
jwwj commentedOk, tested again without facets_pretty_paths installed, and in this case the patch in #15 worked without errors being thrown. So it seems facets_pretty_paths causes the problem. Considering how common it is afaik to use that module, I suggest trying to get this patch to work both with and without facets_pretty_paths installed. I'll put some time into this today to see if I can get it working.
One thing I also noticed, if the base path I want to use in itself is dynamic, then there doesn't seem to be a way to define that with this patch? E.g. if the path to the base path I want to target would be /node/{nid}, there is no way to define that {nid} should be resolved dynamically, and not just used as an url-encoded string.
Comment #20
mariacha1 commentedPatch rerolled at https://git.drupalcode.org/project/facets/-/merge_requests/8.diff
Comment #21
theodorosploumisPatch for #20 attached.
Comment #22
shkiper commentedHi guys,
You may try to use hook_search_api_displays_alter to add the path
Comment #23
amoebanath commentedReroll onto 1.8
Comment #24
cluke009 commentedRerolled this as it reverted this issue https://www.drupal.org/project/facets/issues/3040947
Comment #25
atoll commentedRerolled this for the Facets 2.0.0 module version.
Comment #26
mkalkbrennerComment #27
mkalkbrennerComment #29
atoll commentedComment #30
proweb.ua commented#24
Comment #31
ggamba commentedHello,
should this work with dev version updated 16 Dec 2022? How? Is it included in dev or there is patch to apply?
Thanks a lot!
Comment #32
jonathan_hunt commentedPatch #25 applies to 3.0.0-beta1 and works. However, I have another facet (a) on the same page as facet (b) with base path. facet (a) does not have base path set, and if facet (a) is submitted first, the base path on facet (b) is ignored when the facets are re-rendered.
Comment #33
mistrae commentedHad to switch
isRenderedInCurrentRequestaftergetBasePathor it was always trigerred byisRenderedInCurrentRequest.Comment #34
damienmo commentedAdde missing "use Drupal\Core\Path\PathValidatorInterface;" in FacetForm.php Causing an error on facet edition page.
The error was:
Comment #35
damienmo commentedAdded config_export in Facet.php