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

CommentFileSizeAuthor
#2 vocabulary.jpg19.41 KBkrunar
#2 nodpathauto.jpg6.41 KBkrunar
#2 node-terms.jpg8.63 KBkrunar
#2 alias.jpg8.3 KBkrunar
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

greggles’s picture

Title: pathauto when force lineage » termpath for hierarchical vocabularies
Category: support » bug

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)

krunar’s picture

FileSize
8.3 KB
8.63 KB
6.41 KB
19.41 KB

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.

greggles’s picture

Status: Active » Postponed (maintainer needs more info)

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)?

krunar’s picture

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..)

stevenvu’s picture

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.

greggles’s picture

Title: termpath for hierarchical vocabularies » termpath for hierarchical vocabularies not created when multiple terms are selected
Component: Documentation » Code
Status: Postponed (maintainer needs more info) » Active

@stevenvu: thanks for the description of the problem.

I think there's a duplicate of this somewhere as well...

Manuel Garcia’s picture

suscribe...

we are also seeing this issue, any news?

Manuel Garcia’s picture

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):

            // 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:

/**
 * 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?

if ($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 !

SimonVlc’s picture

Same problem here... is there any solution?

Manuel Garcia’s picture

I couldn't manage with my limited php skills to pull this off SimonVlc...
The token i managed to create only worked on existing nodes... if you were saving a new node or editing one, it'd break. It's as far as I got.

I also think I wasnt the first to try to tackle this issue, seems more complex than what it looks like. This is a job for a guru imho...

I could share the code here but i think it'd do more damage than good, either way, if anyone is interested let me know.

MagicalViper’s picture

Got the same problem. Should the token module be updated to fix this?

momper’s picture

same problem ...

Shane Birley’s picture

I can report this for version 6x-1.1 as well. If multi-select is turn on for the vocabulary, and you select more than one term within the parent vocabulary, pathauto appears to work %50 of the time. It ignores or forgets to use the [termpath-raw] token and only chooses the parent vocabulary.

I will search for the duplicate.

arcaic’s picture

I think I have come to some understanding of this bug....

Suppose you have a vocabulary along the line of the following...

Dogs
  Bulldog
  Spaniel
Cats
  Persian
  Siamese
  Burmese

If for a node you select Cats->Siamese - Selecting both terms.

Then when it comes to creating an alias and pathauto_token_values is called I think it attempts to get the deepest term in the vocabulary for the node using the query beginning 'Select t.tid, t.name from {term_data}.....' and then tries to get all the parent terms to build the path using taxonomy_get_parents_all.

It looks to me that it tries to do this by does this by sorting the results from the query on the term weight and selecting just the first row returned.

The problem is that the weight of the term does not relate to its position in the hierarchy overall but only within the level its is at.

In the above example the weights would be as follows...

Dogs (0)
  Bulldog (0)
  Spaniel (1)
Cats (1)
  Persian (0)
  Siamese (1)
  Burmese (2)

If you select Cats->Persian for your terms then termpath will return Cats/Persian - Ok - Persian will be the first row because of the sort order working properly (0 < 1)
If you select Cats->Siamese for your terms then termpath will MIGHT return Cats/Persian or just Cats depending on the order the db returns them in (weight is the same)
If you select Cats->Burmese for your terms then termpath will return just Cats - Wrong - The sorting on weight meant Cats was returned first and therefore no parents were found.

This means that the success or failure of the building of the termpath can appear fairly random but in reality is based on the weight of the terms when it needs to be more sophisticated.

I don't have a solution for this at present but will carry on looking as I need it to work but its stretching my PHP skills I'm afraid.

Andy

arcaic’s picture

Ok. Here is a workaround that might help some (probably only if you have a static fairly small vocabulary like I do).

If you edit your vocabulary and ensure that parent terms have a weight greater than any of the children then it works ok.

So in the above example if you modify the weights of the parents to something like...

Dogs (10)
  Bulldog (0)
  Spaniel (1)
Cats (11)
  Persian (0)
  Siamese (1)
  Burmese (2)

Then it works ok.

In D6 you have to go in and modify the terms weight using the Operations->Edit>Advanced Options->Weight from the term list. If you drag the terms around using the Ajax interface they all get reset when you save.

Cheers

Andy

Dave Reid’s picture

Status: Active » Closed (won't fix)

Drupal 5 is now unsupported, as well as Pathauto for D5.

momper’s picture

is this solved for d6 - or should we open another issue for the 6.x version of pathauto?

stams24’s picture

I am having this issue for D6

My taxonomy:
-food
--Italian
---pizza
---meatball
---pasta
--Chinese
---sushi
---won-tons

I have a multiple select and have selected:
food, chinese, won-ton

URL Alias I want to use
[catpath-raw]/[title-raw]

What the urls shows up to be:
site.com/food/title

What I would like to show up:
site.com/food/chinese/won-tons/title

jiakomo’s picture

Version: 5.x-2.0 » 6.x-1.5
Status: Closed (won't fix) » Active

This bug is still present in 6.x version. #15 worked for me, as a temporary workaround.

knic’s picture

Same problem here with 6.x-1.5. Can't use #15 as we make heavy use of taxonomy on the site. Does anybody know if this is fixed in 6.x-2.x version?

inkage’s picture

Hi all,

I'm having the same issue on D6 with latest versions of the modules
We'd still need a solution on that, kinda huge limitation :/

cr0ss’s picture

Version: 6.x-1.5 » 7.x-1.x-dev

Here is really simple implementation I've used as part of custom module:

/**
 * Implements hook_tokens().
 */
function custom_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();

  if (!empty($tokens['termspath']) && !empty($data['node'])) {
    if(!empty($options['sanitize'])) {
       $sanitize = $options['sanitize'];
    } else {
      $sanitize = FALSE;
    } 

    $node = $data['node'];
    $replacements[$tokens['termspath']] = $sanitize ? check_plain(custom_get_termspath($node)) : custom_get_termspath($node);
  }

  return $replacements;
}

/**
 * Implements hook_token_info().
 */
function custom_token_info() {
  $info = array();

  $info['tokens']['node']['termspath'] = array(
    'name' => t('Termspath'),
    'description' => t('Custom termspath token.'),
  );   

  return $info;
}

function custom_get_termspath($node) {
  $pathauto = 'terms';

  // field_doc_category is taxonomy you need
  if(isset($node->field_doc_category) && !empty($node->field_doc_category['und'])) {
    $tid = $node->field_doc_category['und'][0]['tid'];
    $parents = array_reverse(taxonomy_get_parents_all($tid));
    $parents_names = array();
    foreach($parents as $term) {
      $parents_names[] = strtolower(str_replace(" ", "-", $term->name));
    }
   $pathauto = join("/", $parents_names);
  }

  return $pathauto;
}

This is not a general solution for any vocabulary you want, but it works as a solution for certain vocabulary pretty well.

cr0ss’s picture

I've just turned this to module: http://drupal.org/sandbox/cr0ss/1268488

Dave Reid’s picture

Version: 7.x-1.x-dev » 6.x-2.x-dev

@cr0ss: Thanks for hijacking the issue and not helping at all to help get that put into Token for D7: #1266928: Add [term:parents] and [menu-link:parents] array tokens

cr0ss’s picture

@Dave Raid, I simply just need this feature now, thats why I need this module. And I do like to help with putting tokens you've mentioned to Token D7.

Fabianx’s picture

@Dave Reid: I believe it was rather bad timing (Sep 1st against Sep 3rd) and while I do agree that it is necessary to create long term solutions that all users can profit from, there are also those users that just need a solution now and don't care about the politics. They'll just use whatever does the job best at that moment. So the posting of the module link here is in my opinion still useful :-).

That said, I believe the proper status would be "won't fix" as your interest clearly lies in getting this into token for D7 and not maintaining this in pathauto.

Best Wishes,

Fabian

Shane Birley’s picture

Issue summary: View changes
Status: Active » Closed (outdated)