url aliases are not supported because of a limitation of core: #118072: Allow query strings in URL aliases
this is a recipe to write a workaround in your custom module:
/* Fix FacetAPI Pretty Paths url alias handling */
/**
* Implements hook_url_outbound_alter().
*/
function mymodule_url_outbound_alter(&$path, &$options, $original_path) {
// Translate resume/[id] to bewberprofil/[id]
if (preg_match('|^search-path/(.*)|', $path, $matches)) {
$path = 'search-alias/' . $matches[1];
}
}
/**
* Implements hook_url_inbound_alter().
*/
function mymodule_url_inbound_alter(&$path, $original_path, $path_language) {
if (preg_match('|^search-alias/(.*)|', $path, $matches)) {
$path = 'search-path/' . $matches[1];
}
}
---
--- original ticket
currently, pretty paths don't respect url aliases.
we can implement outbound url aliasing with the following approach.
@@ -150,7 +151,10 @@ class FacetapiUrlProcessorPrettyPaths extends FacetapiUrlProcessorStandard {
protected function constructPath($basePath, array $segments) {
// Sort to avoid multiple urls with duplicate content.
ksort($segments);
- $path = $basePath;
+ $alias = drupal_lookup_path('alias', $basePath);
+ $path = $alias !== FALSE ? $alias : $basePath;
foreach ($segments as $key => $segment) {
$this->encodePathSegment($segment);
$path .= '/' . $segment['alias'] . '/' . $segment['value'];
the problem is inbound mapping, as with the new url as alias/filter1/filter2 being generated, the system will not find the view any more and result in 404
maybe we need
http://api.drupal.org/api/drupal/modules%21system%21system.api.php/funct...
Comments
Comment #1
dasjoa quick workaround is
Comment #2
dasjoComment #3
uditmahajan commentedThis work-around will only work if one has one search page.
In dynamic Url situation it will fail.
Like in my case. I have custom view for all taxonomy (categories) that use facet api for fields. Now here the alias would not work.
Can you give me any hint here how to get it work...
Comment #4
dasjofor dynamic url situations you will need to adapt the above code to match the dynamic url
Comment #5
dasjowe have been thinking about this problem again, but unfortunately there doesn't seem to be a nice, straight-forward solution.
amongst the problems we are facing is that the drupal alias system doesn't support dynamic parts in paths.
an automated solution would need to figure out which searches (search_api_views for example) use pretty_paths facets. for those search paths we would gather the configured aliases and try to map those in hook_url_inbound_alter analog to #1.
another, simple but not very dynamic solution is described here:
#1240420: To override paths with views, you have to override the internal path instead of alias paths
Comment #6
alCHE commentedAny better solutions know yet?
Comment #7
NIKS_Artreaktor commentedSory, it is not a soluttion.
Sub-path module seems to me looks from the END or url...
So if there are two or many facets - it is already don't work.
I have solution, but i don't know it is better or heavy for system:
I have views path taxonomy/term/%moduleSub-pathauto
Sub-pathauto
admin/config/search/path/subpathschoose
Maximum depth of sub-paths to alias = 4
And every facetted item - already with alias.a href=Comment #8
NIKS_Artreaktor commentedI am using views with path taxonomy/term/%
It is critical to FIX alias of basepath ( for example alias of "taxonomy/term/%" ).
Search api ranges Slider - won't work. It using path, where it was chosen (alias). And when apply facet - with href taxonomy/term/38 ... Chosen facet get lost.
If it so hard to solve, maybe at the end of generating each facet item - we should use pathauto once more?
module Sub-Path helps, but choosing to check every path with big depth - it is maybe hard for system.
Comment #9
dasjothis is a hard problem to solve and just bumping up the priority won't make it easier.
Comment #10
screon commentedWhat is the status of this issue? I am facing the same problem with the website I am building.
Comment #11
dasjoi tend to post updates when i have them, so far nothing has changed
Comment #12
malberts commentedHere's something that might be useful. I haven't tested it a lot as it turned out I don't need pretty paths any more. I tried it with terms using the provided Page Manager term page and with a search view containing a Page display on the term path.
I'm not sure of the implication of the loop in the inbound alter, e.g. performance and i18n. It tries to get the first valid source path by constructing possible aliases from the URL components.
Comment #13
lammensj commented@malberts how are you handling subpages? If your term has children and those children are linked to content that is indexed, I think this won't work.
I used the following code
Comment #14
malberts commented@LammensJ, I never even thought of any of that. My only goal was to get single-level term pages (taxonomy/term/123) to work, but I ended up not needing pretty paths so that's just the result of my initial research. Yours looks much more comprehensive and includes the idea I had (looking up the alias manually).
Comment #15
dasjothanks for all the recipes. i guess we won't be able to fix this within the module but its good to share your workarounds so others can benefit
Comment #16
dasjoAlso see #2287573-2: Use URL alias of taxonomy page when facet displayed on taxonomy page
Comment #17
divined commented#12 and #13 not work if we have hierarchy term alias
We must get last work alias not first!
i.e.
terms{
tid1 => term_name1
tid2 => term_name2
}
alias site.com/term_name1/term_name2/filter1/value1 ....
if we use #12 or #13 we get this urls (inbound hook):
1. term_name1/term_name2/filter1/value1
2. taxonomy
3. taxonomy/term
4. taxonomy/term/tid1 - stop here
5. taxonomy/term/tid1/term_name2 - not found
we must reverse search.
Comment #18
divined commentedFor me work:
Comment #19
dasjoComment #20
leksat commentedComment #21
shiraz dindar#18 in combo with the patch from https://www.drupal.org/node/1922086#comment-7087430 (applied to facetapi_pretty_paths 1.1, because it didn't apply to 1.4) fixes the issue for me of pretty paths not using the path alias in the base URL.
Comment #22
dasjo#18 could be incorporated into facetapi_pretty_paths as a patch.
i'm wondering though, if it should be based on a setting to avoid possible performance hits
Comment #23
sin commentedHere is the patch adding code from #21 as new base path provider and code from #18 with a separate setting.
Maybe we might separate base path URL and facet values with a special symbols instead of slash to avoid multiple drupal_lookup_path() calls?
Comment #24
pianomansam commented@sin, your patch is missing the new plugin file:
plugins/base_path_provider/facetapi_pretty_paths_alias_base_path_provider.incComment #25
sin commentedHere it is.
Comment #26
falco010Patch #25 is working for me, good job guys!
Dont forget to change settings at 'admin/config/search/facetapi_pretty_paths' > 'Alias base path provider' & Use path alias in base URL
Comment #27
Numbatoo commentedI have a view for taxonomy/term/% for my search API facets. Pretty Paths with Patch #25 kind of works for me, when I hover over the facet the URL displays correctly, but or some reason when I click it i'm 301'd to the taxonomy/term/tid version. Example:
Taxonomy Term Name: Gas Meter Rental
Path: taxonomy/term/93
URL Alias: rentals/gas-meter-rental
When I hover over a facet on the page, I see the correct path I want...heres an example for a facet on the gas meter rental page that sorts by a taxonomy term called "Parameter":
rentals/gas-meter-rental/parameter/carbon-monoxide-141
When I click on the facet, I'm 301'd to:
taxonomy/term/93/parameter/carbon-monoxide-141
Any ideas why this is happening? Please let me know if you need more information.
Comment #28
Numbatoo commentedSo I figured out my problem, it looks like the Global Redirect module is the culprit. When I disable the Global Redirect module, the fix in patch #25 works correctly. I tried disabling every setting in the module with it enabled, but that does not do the trick. I looked into the code for the global redirect module, when I comment out these lines everything works except for what this line of code is intended to do (removing unwanted trailing slashes):
Starts on line 215 of globalredirect.module
// Compare the request to the alias. This also works as a 'deslashing'
// agent. If we have a language prefix then prefix the alias
if ($request_path != $prefix . $alias) {
// If it's not just a slash or user has deslash on, redirect
if (str_replace($prefix . $alias, '', $request_path) != '/' || $settings['deslash']) {
globalredirect_goto($alias, $options);
}
}
Edit:
My workaround was to comment out this section, and in my .htaccess add:
RewriteRule ^(.*)/+$ $1 [R=301,L]
I am still learning a lot about drupal and programming in general (self taught)...That being said, I'm not really sure if there is a better solution. Any thoughts you may have about this are appreciated!
Comment #29
sanjayk commentedPatch #25 is working for me as well....
I don't make any changes at admin/config/search/facetapi_pretty_paths > 'Alias base path provider' & Use path alias in base URL
But I have to select 'Reuse term aliases' at 'admin/config/search/facetapi/search_api'
Comment #30
martini9011 commentedThe patch in #25 also did not resolve this issue for me because of the global redirect module. I created a patch that should resolve this over here https://www.drupal.org/node/2813119#comment-11698659
Comment #31
pianomansam commented@martini9011, are you saying you need both the patch in #2813119: Parameters added to path mess with redirect and this patch in order to solve this issue?
Comment #32
vbard commented#25 patch works, thank you sin!
Comment #33
martini9011 commented@pianomansam Yeah, that was the only way to resolve the issue for me
Comment #34
vbard commentedConfirm that #2813119: Parameters added to path mess with redirect works well with #25, thank you guys!
Comment #35
popstas commentedConfirm that patches #25 + #2813119: Parameters added to path mess with redirect works well.
Tested with search_api_ranges, two search pages (/search and /taxonomy/term/%).
Comment #36
lukasss commented#25 + #2813119 working for me
Comment #37
nishruu commentedUsing #25, when I create a menu link like : term-alias/segment/facet1, its alias is not used when I the link is displayed and instead the real path is savec and displayed : taxonomy/term/tid/segment/facet1.
Without the patch, it's actually impossible to create link with parameters. With the patch, it's possible, but the alias is not used.
Shouldn't the alias be used both for facet links and menus ?
Comment #38
nishruu commentedOk, using hook_url_outbound_alter() as explained before, my menu now uses the right aliases.
Comment #39
jedsaet commentedConfirming that #25 works. Thank you! RTBC+1