Closed (fixed)
Project:
Gutenberg
Version:
8.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
31 Mar 2021 at 13:25 UTC
Updated:
3 Feb 2022 at 17:19 UTC
Jump to comment: Most recent, Most recent file

Comments
Comment #2
flyke commentedI confirm the problem. Each autocomplete result is displayed 3 times instead of 1.
I think because there are 3 serparate requests, like this:
- search=mieux&per_page=20&type=post&subtype=undefined
- search=mieux&per_page=20&type=term&subtype=undefined
- search=mieux&per_page=20&type=post-format&subtype=undefined
but none of the results are actually filtered by the type parameter, so each of these 3 requests return the same results.
So as you suggest, maybe we need to change something in
gutenberg/js/api-fetch.js(actually in gutenberg/js/api-fetch.es6.js which should afterwards be converted to gutenberg/js/api-fetch.js)
If you need quick fix you can change
'search-content'insideapi-fetch.jsinto:this works for me.
This is a quick fix for the described problem, but the maintainer of the Drupal gutenberg module should find a way to either make sure only 1 request is happening, maybe without the type and subtype parameters, or make sure that type=post filters the results to actual nodes, and type=term filters the results to actual taxonomy terms.
That would be an actual fix they need to work on, I did not find out how I could do that.
Comment #3
flyke commentedAdded a patch for this that can be used until someone creates a proper fix.
Comment #4
flyke commentedAllright, I think I fixed this the right way now in my new patch.
There ws no need to alter anything in the JS files.
When fixing another one of Gutenberg module's issues (autocomplete results translation) I stumbled upon the correct place to fix this issue too, namely in src/Controller/SearchController.php
This is the place that processes these 3 requests:
- search=mieux&per_page=20&type=post&subtype=undefined
- search=mieux&per_page=20&type=term&subtype=undefined
- search=mieux&per_page=20&type=post-format&subtype=undefined
Now this code did not do anything with the 'type' parameter, which is why there were always 3x the same results.
I have made some adjustments to this code:
- do nothing if type=post-format
- only search nodes if type=post
- only search taxonomy terms if type=term (this was not possible before to search for terms, now it is)
- if the found node or term is available in current language, return that. This fixes #3188514 also.
- Added the result node/term language and type (node or taxonomy term) so it is easier to find the correct result
Relating the other issue as this patch also fixes that issue.
Comment #5
flyke commentedIn some case I got this error:
Notice: Undefined variable: result in Drupal\gutenberg\Controller\SearchController->search() (line 82 of /app/web/modules/contrib/gutenberg/src/Controller/SearchController.php)this is now also fixed in new patch #5.
Comment #7
marcofernandes commentedWe need to figure out a bit more the Gutenberg internals in order to change those request with type parameter.
Ideally it would be possible to search for any "public" site link (nodes, terms, media, etc) but, for now, let's just handle nodes.
I fixed the duplicated search results based on @flyke discovery.
I also added language support.