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.
Hello,
I was tried to remove "Taxonomy Vocabulary" from urls, but with no success.
I was found out below code in file "url_processor_pretty_paths.inc", where I was add this comment
/*. $segment['alias'] . '/'*/ ....with this, I was remove vocabulary from urls, but can't be use because after that links don't have affect to contents.
How I could remove it regularly or what next I should do?
Thanks.
// Add all path segments.
foreach ($segments as $key => $segment) {
$this->encodePathSegment($segment, $segment['facet']);
$path .= '/' /*. $segment['alias'] . '/'*/ . $segment['value'];
}
Comment | File | Size | Author |
---|---|---|---|
#41 | 1981578-fapp_taxonomy_single_alias_mode-40.patch | 12.98 KB | farse |
#24 | 1981578-fapp_taxonomy_single_alias_mode-24.patch | 13.15 KB | dasjo |
#20 | interdiff-6-20.txt | 1.1 KB | mh86 |
Comments
Comment #1
dasjocurrently, this just won't work. you need a two-way mapping, so that the path always translates back to a valid assignment of facets.
please explain, what exactly you want to accomplish, because the code doesn't make sense
Comment #2
luo8 CreditAttribution: luo8 commentedhello dasjo,
thank you for your reply.
I mean if there is any way to change urls http://drupal.org/taxonomy-voc/taxonomy-item to http://drupal.org/taxonomy-item ?
Thanks for your help.
Comment #3
cm_is CreditAttribution: cm_is commentedHi,
would also really favor for a solution to remove the taxonomy vocabulary from the url. If more than one facet is applied eg. in commerce filtering first for a manufacturer and then further refining for a category, the urls get blown up unnecessary.
products/field_brand/some-brand-1/field_category/some-category-52
vs.
products/some-brand-1/some-category-52
By being able to remove the taxonomy vocabulary the url would get much more readable, shorter, It would also represent a SEO best practice.
Greetings
Comment #4
dasjoi'm changing this to a feature request which has been discussed with mh86. he's not yet working on it & but explained me an idea for enabling such a feature.
it's basically a follow up to #1863774: Taxonomy Pathauto coder which will get rid of the vocabulary name and leave just the term alias within the url.
in order to make it happen, we will also need to change some url processor logic, because currently its is tied to 2-part url segments per facet.
feel free to get in touch, if you want to provide funding in order to speed up this process
Comment #5
heshanlkI had the same issue and I end up with creating a new facetapi url processors, it is not a generic solution which I have my taxonomy hierarchical as a configurable array(I know how to match my taxonomy hierarchy and my url pattern). So only issue on this task I think determining which facets belongs to which URL part and that's tough.
Comment #6
mh86 CreditAttribution: mh86 commentedFinally found some time to work on this issue. Attached is a first working patch with a few known issues.
The patch introduces a new 'single term alias' mode where the alias is just constructed by the term name. This requires the pathauto pattern to be set to taxonomy/[term:name] and to re-generate all term aliases.
Unfortunately the assumption that an facet alias always consist of [facet-name]/[value] is very deep in the Facet API Pretty Paths system. To get it working it required some hacking in the class FacetapiUrlProcessorPrettyPaths and I introduced a 'resolveFacetByValue' callback that the coder plugins can implement to directly load the facet by a single URL argument (in our case the term name).
There are currently a few issues with the patch:
Comment #7
mh86 CreditAttribution: mh86 commentedAnd one more thing:
The system does not support multiple facets for the same search with the same vocabulary. So the mapping between vocabulary and facet should be unique.
Comment #8
dasjohi mh86,
thanks a lot for approaching this :)
maybe it makes sense, that we try to get rid of the assumptions around [facet-name]/[value] that we are making at the moment. i can see that the patch already tries to do that at a certain level, but i think we could go a bit farther:
i'm thinking of treating $args as a stack that gets consumed by a chain of FacetApiPrettyPathsCoderDefault (sub)classes. Every coder ties to decode from the current stack state, and will either consume one or many parts of the arg stack.
Comment #9
cm_is CreditAttribution: cm_is commentedsounds great, will give it a try and report back any findings!
Comment #10
mh86 CreditAttribution: mh86 commentedThanks for the feedback.
Having a chain of coder classes that decode the URL arguments sound interesting, although I don't know how exactly it should/can look like. Maybe we can discuss this in person when we meet each other the next time.
I'm still struggling a bit with the base path issue and I've just realized that there is possibility to retrieve the base path from the Facet API adapter, so it seems like we could use $this->adapter->getSearchPath() in FacetapiUrlProcessorPrettyPaths:fetchParams().
Is there any reason to not use this function?
Comment #11
dasjoyeah, i'd be happy discuss this in person.
regarding base path... that's a complex issue, see #1861786: Fix base path issues
Comment #12
mh86 CreditAttribution: mh86 commentedthe thing with the base path is really pretty complex. Spent some time today to find alternatives. Unfortunately I couldn't get it working in a general way, but at least I know now why it isn't working with the Search API.
The Search API Facet API Adapter tries to retrieve the base path from the current Search API search, but at the time the Facet API and the Facet API Pretty Paths system is initialized, the current search isn't yet set. So SearchApiFacetapiAdapter::getSearchPath(); returns $_GET['q'], which isn't save.
Comment #13
dasjowe could also include base path settings within the pretty paths module where you can set your own base path or select from a set of available strategies...
but i guess this should be discussed within a separate issue, probably as a follow-up to #1861786: Fix base path issues
Comment #14
mh86 CreditAttribution: mh86 commentedI'll come back to #1861786: Fix base path issues once I have something working. It needs to be fixed in the Search API first and I think I know already how the base path issue can be solved.
Comment #15
PedroMiguel CreditAttribution: PedroMiguel commentedThis is working fine for me, if someone need to make validation trough view global null argument you need to make a few changes on -/sites/all/views/modules/taxonomy/views_plugin_argument_validate_taxonomy_term.inc
There is a new option called "pathauto" on the taxonomy validation, who check the name on your path and validate.
Hope this can help somenone
Comment #16
dasjoThanks for pointing that out!
Please try to post a patch next time so it's easier to reuse, understand your changes and there's less clutter on the issue page :)
Comment #17
kitikonti CreditAttribution: kitikonti commentedIs #15 a solution for this issue or is it something different?
Comment #18
dasjoPlease see #6 for the latest solution to this issue and report back your findings
Comment #19
kitikonti CreditAttribution: kitikonti commentedi cant get #6 to work. i have patched the module, set the pattern and regenerated all aliases. is there anything else i have to do? and will this also work if i want to filter on multiple terms?
Comment #20
mh86 CreditAttribution: mh86 commentedI have a small reroll of my patch from #6.
This patch is based on a fix in the Search API that allows us to safely retrieve the base path ([#2159827). Sorry for not yet re-opening #1861786: Fix base path issues - it's already a bit complicated to keep everything separated.
By retrieving the base path via the adapter we also avoid possible clashes between the base path and terms with the same alias.
Comment #21
fagoI recently had a quite similar need and solved the unique-term-name exactly the same way, +1 on doing that. However, how we should clearly notify users somewhere that this url alias pattern must be configured and in *active* use or the stuff will fail for them. Maybe, we could put a warning message to the setting?
Extending the facet coders that way makes sense + having the method in the base class does not make it an API change given it's required to use the base class? I guess in practice every coder does.
Besides that, here a review - mostly nitpicks:
Should use protected so that inherited classes can use it?
Summary should fit in one line.
Summary should fit in one line.
Summary should fit in one line.
Summary should fit in one line.
Description should be a line below.
Summary should fit in one line.
Should be protected?
Once we know our facet_path now, we should process the args in the logical order, i.e. from the beginning to the end? Or is there any reason left to do it reversed?
This should use a static lookup map from alias to facet as it does for vocabularies?
Deprecated?
Should specify the class + use a new line for the summary.
1 line summary.
Comment #22
Exploratus CreditAttribution: Exploratus commented+1
Comment #23
rv0 CreditAttribution: rv0 commentedPatches should be rolled (& tested) against latest dev afaik (and it doesn't apply to latest dev.
Comment #24
dasjoattached a simple re-roll using git rebase towards the latest dev version
Comment #25
rv0 CreditAttribution: rv0 commented@dasjo: great.. working fine for me!
Only issue I see is that every path begins with search/site/..
My search pages have custom urls, so thats not correct I think. Is that the base path issue mentioned above?
In the other taxonomy coder patch, I think the path was retained (see #2160497: Date coder for pretty paths)
Comment #26
dasjoyeah those nasty base path issues, i hope we can get those finally fixed for all the use cases :)
could you have a look at
#2159827: Fix search base path in Facet API adapter
#1861786: Fix base path issues
Comment #27
rv0 CreditAttribution: rv0 commented@dasjo
#2159827: Fix search base path in Facet API adapter is for search_api, which i'm not using (using standalone apachesolr integration)
#1861786: Fix base path issues is closed and committed, so I'm not sure what to look for there.
Sorry for the slighly off-topic, but the paths are retained with the patch in #2160497: Date coder for pretty paths (i just restored it to test), and I cant see why they don't here.
Comment #28
dasjoI'd say that's because of the following line that's being added by the patch:
so that doesn't seem to work for the way that you are altering the search path right now?
could you share a bit of the way how your search paths are set up with apachesolr module at the moment?
ideally, the right base path should be returned from the facet api adapter using the getSearchPath method.
Comment #29
dasjoso we should look at FacetapiUrlProcessorPrettyPaths::getBasePath():
http://drupalcode.org/project/facetapi_pretty_paths.git/blob/refs/heads/...
it has some logic to get search_api's base path.
i asked nick_vh on apache_solr and it seems you should be able to get the search_path through the adapter and its search environment
Comment #30
rv0 CreditAttribution: rv0 commentedSorry for not getting back at this, turns out in my usecase I did not need this patch after all. If time permits I will look back into it.
Comment #31
philipz CreditAttribution: philipz commentedI'm trying patch #24 but I'm not sure if it's not working for me or I didn't set something right. Anyway I have standard pretty facet paths working and as soon I apply the patch (without any configuration changes) clicking on facets does not activate them and I get all nodes without filters.
Maybe some recent chages to facetapi or search api broke this patch?
I'm not even discussing next step to remove facet aliases from url at this point.
Comment #32
dasjocan you describe which urls are generated for the facets with the patch.
you'll need to make sure that the terms have url aliases associated with them.
Comment #33
philipz CreditAttribution: philipz commentedOK I'll try to describe step by step what is going on.
Before applying patch #24 I have a facet and one of links is:
/products/category/lamps-224
Then I apply the patch and enable Reuse term aliases. The same link becomes:
/products/category/lamps
so something is working ;)
My terms aliases are set to: taxonomy/[term:name].
But after applying the patch regardless of "Reuse term aliases" option the search page does not filter nodes based on the path. Just as if I have opened main search path.
Comment #34
dasjosorry for not getting back earlier, could you fix your problem?
can you describe how the search is created? are you using panels or any other layer in between?
Comment #35
philipz CreditAttribution: philipz commentedUnfortunately I gave up and sticked with default pretty paths.
Comment #36
dasjowould be great if someone could address fago's comments in #21 and roll a new patch. i'd be willing to include this within the next release
Comment #37
Narhir CreditAttribution: Narhir as a volunteer commentedHello,
I'm also having same problem, trying to generate URL's without any aliases in them just the taxonomy term names:
I explained my process in here: http://drupal.stackexchange.com/questions/175822/search-api-search-widge...
But I tried to somehow substitute the facets, with taxonomy pages (but it didn't worked out) and I'm getting back to the facets.
With current version and patch 24 I'm able to generate urls such us:
http://localhost/search/field_city/{name_of_region}/field_city/{name_of_sub_region}/field_city/{name_of_city}?search_api_views_fulltext={yorkshire terrier}&field_city=1031
But I'm trying to achieve
Or in case of category type search
http://localhost/home-garden/pets/dogs/{name_of_region}or{name_of_sub_region}or{name_of_city}/search?s={yorkshire terrier}&field_city=1031
I'm super stuck with this and I'm currently running in circles so if anyone could suggest me the best approach to get that kind of clean facets url that would be great, I assume that I would need to write a my own hook for sort? not sure how to use the hooks described or what can be in them. are there any examples ? or how can I figure out what can I do in specific hook ?
Comment #38
ajka CreditAttribution: ajka as a volunteer commentedis there any solution for the initial problem "Allow to remove 'Taxonomy Vocabulary' from urls" that made it into the official release or any new separated module?
Comment #39
pmkanse CreditAttribution: pmkanse commentedany update on this to get URL structure without 'Taxonomy Vocabulary' from in URL
Comment #40
farse CreditAttribution: farse at Zoocha commentedI managed to get this to work after some fiddling.
These are the steps I took:
- The lastest dev version of this module plus patch #24. There was one discrepancy with the patch and the dev code so I had to apply the patch code in url_processor_pretty_paths.inc fetchParams() manually. Namely I had to do
$params['q'] = $this->basePath;
instead of$params['q'] = $this->pathWithoutSegments;
patch in comment #41.- The patch above didn't work without the patch from https://www.drupal.org/project/search_api/issues/2159827#comment-11880360 I just used the patched module to avoid any issues. This solved the basePath issue.
- I had to set Default path pattern (applies to all vocabularies with blank patterns below) in /admin/config/search/path/patterns to
taxonomy/[term:name]
. Then I had to recreate my URL aliases for the taxonomy terms. This then got my facet urls working when I went to the desired URL manually.- Now the last bit that got me so that my facet block links were created properly in /admin/config/search/facetapi_pretty_paths I had to change Base path provider from Default base path provider to Adapter base path provider
- make sure to reindex, clear caches, etc just to make sure it's all good.
Now I just need to do a bit more testing, but so far so good, I can go to the facet urls without any vocab prefixes and I have multiple vocabs in my facets and I can select multiple facets and they all seem to be working well!
Comment #41
farse CreditAttribution: farse at Zoocha commentedsorry this patch is meant to be for comment #40 but I couldn't find a way to add the file to the comment and then I couldn't delete this file after I uploaded it..
Comment #42
tibezh CreditAttribution: tibezh at Drupal Ukraine Community, jobiqo - job board technology commentedThanx @farse!
The patch from #41 works as expected.