I'm trying to get aliases for my forums set up, but I'm getting inconsistent results. I have the following vocabularies;
*Forum
*Language
*Free Tag
And the following alias for Forum topic paths: forum/[catpath]/[title]
I was a little confused by the explanation for catpath ("The name of the lowest-weight category that the page belongs to") as "lowest weighted" could mean "lowest number" (ie "-10") or "lowest-ordered" ("10")). I've tried ranking my categories both ways, but I end up with a mix of aliases (this is after deleting all aliases in the db):
| 8133 | node/67 | forum/web_2_0_stuff
| 8132 | node/61 | forum/english/top_5_contribs_block
| 8135 | node/71 | forum/technical_issues/feature_discussion/tagging/tag_organization
As you can see, the first one has no category path, the second uses the language category, and the third is correct.
I dug into the code and found this clue:
// And now taxonomy, which is a bit more work
if (module_exists('taxonomy') && is_array($node->taxonomy) && count($node->taxonomy) > 0) {
$first_term_id = FALSE;
// We loop through the array assuming it's in wheigh order, which is false, but close enough TODO: fix that
// I'd use more descriptive variables, but the content isn't always a tid
foreach ($node->taxonomy as $key => $value) {
Fixing this seems to be beyond me, I tried forcing the vocid to 1 (the vid for the Forum taxonomy) but it didn't have any effect.
It either needs to actually be using the weight to determine which one to use, or (better yet) there needs to be a way to set which vocab to use.
Until then, this otherwise super great module is unusable for me.
Thanks,
maj
Comments
Comment #1
gregglesI agree this is a problem.
I don't plan to work on this for pathauto 5.x-1. For pathauto 5.x-2 this would be a bug in the token module (since pathauto just uses the values that token gives and I believe that token will have this bug as well since it's largely copied from pathauto).
I don't currently plan to work on fixing this bug because I don't see it as critical and because it is somewhat difficult to get right. If anyone else wants to work on it then feel free to.
Comment #2
micheleannj commentedHmm, I appreciate how much you've put into this module, but I'm not sure how else you could define "critical"...
Like I said, I'm happy to try and fix it-- would you be able to give me some help if I take this on as a task?
I think the 'easy' way is to just make sure the array is sorted by weight, which shouldn't be too hard. The better way would be to add a pulldown that allows users to select the vocab...
I'll see how far I can get with the easy way first, just so the module is usable.
Thanks!
Comment #3
gregglesSee http://drupal.org/node/92900 for more details and especially http://drupal.org/node/92900#comment-165168 for more details on the subject.
The reason I say that it's not critical is that the current code handles most uses of taxonomy. Your situation is somewhat rare (though I'm sure it doesn't feel that way to you).
The array is sorted by weights in most cases. But in some cases it is not. Therein lies the fun. I would suggest that you "normalize" the array (making tags look more like the taxonomy array, and sorting everything in the process). I don't think this needs any further UI like a dropdown. That said, I could see how a system that allows you to specify which vocab you are referring to when you say [vocab] or [cat] or [catpath] could be useful so exploring that as a new feature would also be good (though that would go in token module).
Comment #4
gregglesJust changing the title to be a little more descriptive.
Also, if you are working on it then you could select the "assigned" to yourself to let others know that.
Comment #5
micheleannj commentedWell, here's my hack. Note that this *only* works for situations like mine: you have forum posts with a Forum vocab and you want the urls to be aliased by the Forum vocabulary only. The vocab must be a non-free tag and you can't be using catpath or cat for any other vocabs... like I said, a hack, but it makes my site work while I try to come up with something more generalized / pretty.
// And now taxonomy, which is a bit more work
if (module_exists('taxonomy') && is_array($node->taxonomy) && count($node->taxonomy) > 0) {
$vid = 1; // force Forum vocab, replace with your ID
$vocabulary = taxonomy_get_vocabulary($vid);
$placeholders[t('[vocab]')] = pathauto_cleanstring($vocabulary->name);
$terms = taxonomy_node_get_terms_by_vocabulary($node->nid, $vid); #there isn't a way to get parents for a vocid?
$ttid = '';
$catpath = '';
foreach ($terms as $term) {
$ttid = $term->tid;
break; //gotta be a better way to do this, arraypop?
}
$parents = taxonomy_get_parents_all($ttid);
foreach ($parents as $parent) {
$catpath = pathauto_cleanstring($parent->name).'/'.$catpath;
}
$placeholders[t('[catpath]')] = $catpath;
} else {
$placeholders[t('[cat]')] = '';
$placeholders[t('[catpath]')] = '';
$placeholders[t('[vocab]')] = '';
$placeholders[t('[catalias]')] = '';
}
The next step seems to be changing the form to accept a vocabulary for the cat / catpath. Of course it's more complicated if we want to support free tag vocabs, but I'm not sure if that even makes sense since we're not supporting multiple paths?
Comment #6
gregglesWell, people expect it to work with freetags so I think it should.
As you point out, this works for your case but not all. It's a tricky problem ;)
Comment #7
gregglesNew processing to get taxonomy terms is much more consistent with Token+Pathauto 5.x-2.0. So, I'm closing this issue. Please upgrade and test that out.