I've set up hierarchical select with one of my vocabularies and have set "Save term lineage". The terms in that vocab look like this:

- Blue
- - DVD
- - CD

What I want is an URL like this:
blah.com/blue/dvd/node-title

With a pathauto setting of [termpath-raw]/[title-raw], I get:
blah.com/blue/node-title

With a pathauto setting of [save-lineage-termpath-raw]/[title-raw], I get:
blah.com/blue-dvd/node-title

I am lost! What do I need to do to get all my parent and children terms into my URL? Thanks!

Comments

Wim Leers’s picture

Status: Active » Postponed (maintainer needs more info)

Hm, I was under the impression that [save-lineage-termpath] worked similary to just [termpath], i.e. that each item in the lineage would be separated by slashes, as you were expecting. I guess I'm remembering that incorrectly.

Just to be sure that this works with [termpath], please switch over to [termpath] for a sec, ignore the incorrect order, and let me know if there indeed slashes are used.

If it's got the same problem, then I'm afraid this is a pathauto limitation. We could of course hack the code a little bit to make it work for you.

leenwebb’s picture

Status: Postponed (maintainer needs more info) » Fixed

Huh... this is totally weird. I tried this like FIVE times yesterday and got the results I posted above. But I just changed to [termpath] and it was fine and then changed to [save-lineage-termpath] and now it is also fine. So, uhhh... Fixed? By your psychic powers? Sweet!

leenwebb’s picture

Status: Fixed » Active

Curiouser and curiouser. It worked, but now it doesn't*, and I haven't changed any settings. OK, so, if I use
[termpath]/[title-raw], I get:

blah.com/blue/node-title

With no children. Just the parent term.

With [save-lineage-termpath-raw]/[title-raw], I get:
blah.com/blue-clothing-shirt/node-title

(Instead of blue/clothing/shirt/title)

Where might I go in Pathauto to make those - into /? In the general settings it uses - but I think that setting is for spaces, not separate terms.

* As in: 10 nodes that I put in had the correct paths, but the 11th and 12th don't.

Wim Leers’s picture

Title: URL alias is only showing top parent, no child terms » Allow the separator for tokens to be set through a variable
Assigned: Unassigned » Wim Leers
Category: support » task

*huh* :O Maybe you've got some module interfering with pathauto then? This all sounds very weird.

Your pathauto settings are fine, there's nothing you can change. The hacks I was mentioning were in hs_taxonomy.

However, I've found the cause:

/**
 * Implementation of hook_token_values().
 */
function hs_taxonomy_token_values($type, $object = NULL, $options = array()) {
  static $hs_vids;
  static $all_vids;

  $separator = variable_get('pathauto_separator', '-');

That last line is the cause of course. Just change that one line for a second and it'll work as expected.

I guess I should change that to something like:

$separator = variable_get('hs_taxonomy_separator', variable_get('pathauto_separator', '-'));

Then you could set the hs_taxonomy_separator variable and be done with it.

leenwebb’s picture

Ugh, this is SO weird.

A) I changed that - to a / in the code but it still gives me - in the URL. I even cleared cache (I have no idea if that would do anything, but I view cache as some sort of voodoo so I figured it couldn't hurt).

B) I deleted all the content aliases, then asked Pathauto to regenerate them. Using [save-lineage-termpath-raw]/[title-raw], all of the re-generated aliases had NO TERMS at all! Just straight-up blah.com/node-title. (Which is what I have set as the default "if nothing else is specified" pathauto setting.)

C) I deleted all of them again and re-generated using [termpath-raw]/[title-raw]. This time I get the top-most parent for all of them, like blah.com/blue/node-title. But ONE of them (just one!) has the proper URL of blah.com/blue/cd/name-of-cd.

WTF drupal: Are you trying to make me cry?

Wim Leers’s picture

A) The second parameter of variable_get() is the default value, if you've set "-" through the pathauto settings, it'll still use that.

B) WTF?

C) Bah.

Just make the change I mentioned in A and hope for no weirdness this time …

leenwebb’s picture

SUCCESS! The low-tech hackity change to $separator = '/'; does the trick.

(FWIW, using pathauto's bulk alias feature to regenerate these aliases is totally wack. (B) above is very consistent for me -- they are generated as blah.com/node-title with no terms at all. But then if I go into the node edit the path box is empty, and on saving it will generate the (now-correct) full-of-terms URL. Doesn't matter for the site I'm setting up, as I only have 12 nodes so far. But... weird.)

vthirteen’s picture

Wim Leers said:

I guess I should change that to something like:
$separator = variable_get('hs_taxonomy_separator', variable_get('pathauto_separator', '-'));
Then you could set the hs_taxonomy_separator variable and be done with it.

where am i supposed to set the hs_taxonomy_separator variable?

vthirteen’s picture

$separator = '/';
it doesn't work for me... the slash gets stripped and the final URL is something like /term1term2/nodetitle

Wim Leers’s picture

@vthirteen: you should add the slash to the allowed characters then.

Wim Leers’s picture

Status: Active » Fixed

Implemented, documented, patches attached and committed:
- D6: http://drupal.org/cvs?commit=244596
- D5: http://drupal.org/cvs?commit=244598

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

ryantollefson’s picture

Category: task » support

I'm getting the same results as vthirteen.

I'm running 6.x-3.x-dev and when I try to use: [save-lineage-termpath-raw:5] I am getting the "-" instead of a "/" as a separator. I tried changing the $separator = '/'; as suggested, but like vthirteen I then get /term1term2/ instead of /term1/term2/. I also tried to add the '/' as an allowed character in pathauto, but that didn't seem to make a difference.

Has anyone confirmed that this works with a "/"? Perhaps I am missing something simple here? Thanks in advance.

Uersu’s picture

The current readme.txt says: "You can override this by setting the hs_taxonomy_separator
variable."

Please, also mention (or add a reference) how/where I can add/set the variable 'hs_taxonomy_separator'. I know that there is a 'variable', but I am not sure how to easily add a variable to this table without having to write a module.

Or do I completely misunderstand something?

-enzo-’s picture

Hello Guys

I did the following small module to set the hs_taxonomy_separator

<?php

function mymodule_menu(){
	
	$items = array();

  $items['admin/settings/mymodule'] = array(
        'title' => 'mymodule Settings',
	    'description' => 'Configure mymodule Settings',
	    'page callback' => 'mymodule_settings_page',
	    'access callback' => TRUE,
        'access arguments' => array('administer site configuration')
    );
    
  $items['admin/settings/mymodule/general'] = array(
        'title' => 'mymodule Settings',
	    'description' => 'Configure mymodule Settings',
		'page callback' => 'drupal_get_form',
    	'page arguments' => array('mymodule_admin_settings'),
        'access callback' => TRUE,
        'access arguments' => array('administer site configuration'),
   		'type' => MENU_DEFAULT_LOCAL_TASK,
    	'weight' => 0,
  );    

 return $items;
}

/**
 * The default tangle_cdn settings page.
 */
function mymodule_settings_page($op = NULL) {
  $output = drupal_get_form('mymodule_admin_settings');
  return $output;
}


/**
 * Form builder. Configure Tangle CDN
 * 
 * @ingroup forms
 * @see system_settings_form()
 */

function mymodule_admin_settings() {
	
	$form['hs_taxonomy_separator'] = array(
		'#type' => 'textfield',
		'#title' => t('Hierarchical Select Separator'),
		'#required' => TRUE,
		'#description' => 'Separator for Hierarchical Select Terms, used instead of Path Auto separator',
		'#default_value' => variable_get('hs_taxonomy_separator', variable_get('pathauto_separator', '-'))
	);
	
	return system_settings_form($form);
	
}	

The problem is I want to use "/" as separator, but doesn't matter want separator I use always is removed :S

Any idea.

enzo

pupp’s picture

As bad as this sounds, i simply commented out that line in hs_taxonomy and added $separator = '/'; it works and i've already wasted too much time on this. Hopefully this gets fixed.