termpath for hierarchical vocabularies not created when multiple terms are selected
| Project: | Pathauto |
| Version: | 5.x-2.0 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Hello
First of all, i have look around for a similar description of the case below but i havent found anything. If there is a post i have missed..please point me there and close this one
I have the following category structure
Vocabulary
-TermA
--TermB
When i create a node i want to belong both to TermA and TermB so that it will appaer both on /taxonomy/termA and taxonomy/termB (if this is wrong tecnhique of there is another way to bypass this let me know)
I have set pathauto to [vocab-raw]/[termpath-raw]/[title-raw] and the alias that is create is
Vocabulary/TermA/node-name.
I want it to be like "Vocabulary/TermA/TermB/node-name"
Is there a way to have the second format of tha alias?
Thank you

#1
I just want to make sure I understand your vocabulary.
So, TermA is in "Vocabulary" and is a top level term. TermB is in Vocabulary and has "TermA" as it's parent. So, "Vocabulary" has "hierarchy" enabled - is it single or multiple?
I believe that the settings you have are right for what you desire, so if we can't get this working then it is a bug.
Thanks for the report.
(I didn't respond to the first part about taxonomy/termb because that's not directly related to Pathauto module - try using taxonomy/term/TID/0 and see if that gets you want you want)
#2
thanks for the reply.
The vocabulary is as you have described. The Hierarchy is Multiple. I have tried also with single and it has the same result (not sure if this is wrong with single).
i have attached a number of pictures to show you the case. Of this is the actual vocabylary and not TermA, TermB but the structure is again the same.
#3
I just tried to reproduce this and couldn't. I followed your steps and it worked fine on my site. Are you using any other contributed modules that change your vocabulary (multiple hierarchy? category module)?
#4
Hi,
thanks for your reply and sorry for not answering so far...was a little busy.
Yes i have multiple heirarchy and ubercart (it has a vatalog vocabulary for which im making the allias)
It seems that the problem is caused by the weight. Let me try to explain this.
The Terms in my Vocabylary are
LEVEL ||TERM NAME || WEIGHT || ALLIAS
1 || Consumables || 1 || consumables
2 || -- Cartridges Inkjet || 1 || consumables/cartridges_inkjet
2 || -- Toner Laserjet || 2 || consumables/toner_laserjet
For the node allias i have select [termpath-raw]/[title-raw]
Now when i create a node for Cartridges Inkjet the url from pathauto is set to consumables/cartridges_inkjet/nodename
when i create a node for Toner Laserjet the url from pathauto is set to consumables/nodename
The Alias is created correctly only when the terms of level2 have the same or smaller weight from the term of level 1 that it belongs.
Is this the way it should work, or i am doing something stupid with the terms weight?
Thank you again
(sorry if i havent explaint it very well..i hardly understand myself to be honest..)
#5
I have the same problem.
I'm also using Ubercart so it may be a problem with that module. Here's a little explanation about the setup.
I have a single hierarchy setup:
Catalog(Vocab)
- Term 1
-- Term 2
-- Term 3
pathauto is setup as follows:
node settings:
[type]/[termpath-raw]/[title-raw]
Categories settings:
Hierarchy = single
Multiple Select = ON
I then create some content, falling under Term 2.
THE BUG
When only one category is selected then autopath works:
http://testteach.co.uk/product/11-plus/verbal-reasoning/electronic-paper...
When multiple categories are selected then autopath doesn't work:
http://testteach.co.uk/product/11-plus/test-product-2
Hopefully that gives you enough information.
#6
@stevenvu: thanks for the description of the problem.
I think there's a duplicate of this somewhere as well...
#7
suscribe...
we are also seeing this issue, any news?
#8
OK, I have been digging a bit into the subject, apparently token doesn't provide catpath for node any more see the comments inside token_node.inc (line 124):
<?php// The 'catpath' (and 'cat') tokens have been removed, as they caused quite a bit of confusion,
// and the catpath was a relatively expensive query when the taxonomy tree was deep.
//
// It existed only to provide forward-compatability with pathauto module, and
// for most uses of token.module, it was a relatively useless token -- it exposed
// a list of term names formatted as a URL/path string. Once pathauto supports
// tokens, *it* should handle this catpath alias as it's the primary consumer.
?>
This is provided by pathauto now, OK, so I went and tried to find the issue in the pathauto.module, I assume the problem must be somewhere in here:
<?php
/**
* Implementation of hook_token_values() for Pathauto specific tokens.
*/
function pathauto_token_values($type, $object = NULL) {
if (module_exists('taxonomy')) {
if ($type == 'taxonomy' || $type == 'node' || $type == 'all') {
_pathauto_include();
switch ($type) {
case 'node':
// We're on a node and it's a book and it has a parent? Get the book path alias
if (module_exists('book')) {
if ($object->type == 'book' && $object->parent) {
$values['bookpathalias'] = drupal_get_path_alias('node/'. $object->parent);
}
else {
$values['bookpathalias'] = '';
}
}
$vid = db_result(db_query_range("SELECT t.vid FROM {term_node} r INNER JOIN {term_data} t ON r.tid = t.tid INNER JOIN {vocabulary} v ON t.vid = v.vid WHERE r.nid = %d ORDER BY v.weight, t.weight, t.name", $object->nid, 0, 1));
$category = db_fetch_object(db_query_range("SELECT t.tid, t.name FROM {term_data} t INNER JOIN {term_node} r ON r.tid = t.tid WHERE t.vid = %d AND r.nid = %d ORDER BY weight", $vid, $object->nid, 0, 1));
$category->vid = $vid;
// In the realm of nodes these are terms, in the realm of Taxonomy, cats
$label = 'term';
case 'taxonomy':
default:
if (!isset($category)) {
$category = $object;
}
if (!isset($label)) {
$label = 'cat';
}
if (isset($category->tid)) {
$separator = variable_get('pathauto_separator', '-');
$parents = taxonomy_get_parents_all($category->tid);
array_shift($parents);
$catpath = '';
$catpath_raw = '';
foreach ($parents as $parent) {
// Replace any / characters in individual terms which might create confusing URLs
$catpath = pathauto_cleanstring(check_plain(preg_replace('/\//', '', $parent->name))) .'/'. $catpath;
$catpath_raw = pathauto_cleanstring(preg_replace('/\//', '', $parent->name)) .'/'. $catpath_raw;
}
$values[$label .'path'] = $catpath .'/'. check_plain($category->name);
$values[$label .'path-raw'] = $catpath_raw .'/'. $category->name;
// We only do this for taxonomy because token already provides the [term] value but has problem with [cat] TODO: fix that?
if ($type == 'taxonomy') {
$values[$label] = check_plain($category->name);
$values[$label .'-raw'] = $category->name;
}
$values[$label .'alias'] = drupal_get_path_alias('taxonomy/term/'. $category->tid);
if (!strncasecmp($values[$label .'alias'], 'taxonomy', 8)) {
$values[$label .'alias'] = $values[$label];
}
}
else { // Provide some defaults if they aren't set.
$values[$label .'path'] = '';
$values[$label .'path-raw'] = '';
$values[$label .'alias'] = '';
}
}
return $values;
}
}
}
?>
If i understand correctly the code (im a tourist php programmer), catpath is not available for node aliases or I'm i getting it totally wrong?
However, if you see the pathauto_token_list() function, termpath is listed for node, is this why we are getting frustrated or I'm I way off?
<?phpif ($type == 'node' || $type == 'all') {
$tokens['node']['termpath'] = t('As [term], but including its supercategories separated by /.');
$tokens['node']['termpath-raw'] = t('As [term-raw], but including its supercategories separated by /. WARNING - raw user input.');
$tokens['node']['termalias'] = t('URL alias for the term.');
}
?>
I understand this can get messy if the node has terms from different term hierarchies, but perhaps we could have it anyway, and warn the user that it would only work properly if the node only has terms from one hierarchy? Just a thought, I think it'd be great to have it as a possibility for node aliases.
Again, I'm self-taught PHP tourist, so sorry if I'm causing confusion !