I got a node type "Public Place" with the field field_city which is a hierarchical taxonomy reference field. The structure of this taxonomy is zone/region/city.

I want to set URLs as described here: domain.tld/zone/region/city/node_title

In the Pathauto patterns page I put [node:field_city]/[node:title]. But it outputs URLs built like this: domain.tld/zone-region-city/title

Hierarchical values should be separated with a / instead of the standard "empty space" separator (-).

Would it be possible to implement?

Comments

RumpledElf’s picture

Try the [node:field-yourtaxonomyfieldname:name-tree]

Works for me, mostly. But that's another issue.

cesareaugusto’s picture

Hi giraffian! Thanks for your quick reply!

Try the [node:field-yourtaxonomyfieldname:name-tree]

My taxonomy reference field name is field_citta. I tried this [node:field_citta:name-tree]. But I got an error which says this is not a valid token.

Works for me, mostly. But that's another issue.

Where do you think I should issue this?

RumpledElf’s picture

That only works for single-select taxonomies, if you've got it multiselect you can't do that.

I have a custom token on d7 to let you build a path from the *first* tree in a multiselect taxonomy so I didn't notice that particular problem until starting a new site ...

cesareaugusto’s picture

That only works for single-select taxonomies, if you've got it multiselect you can't do that.

Would it be implementable? In case it will never be possible to have it multiselect in Drupal... how could I select just the last child term in the hierarchy?

Eg: if I got the hierarchical terms State>Region>City, how to render the URL: domain.tld/city/node_title

ANDiTKO’s picture

Try [node:taxonomy-MyTaxonomyName]/[node:title]

Replace the MyTaxonomyName with your taxonomy name.

nrdmagnus’s picture

Category: bug » feature
Priority: Normal » Major

For Taxonomy term paths you can use the Imploded token, like explained ahead. But for Content paths you just don't have such an option! So the feature request would be: Imploded token for any Term reference field.

Trailed Taxonomy term paths:

  1. Go to URL aliasesSETTINGS (admin/config/search/path/settings)
  2. Open PUNCTUATION fieldset and for Slash (/) select No action (do not replace)
  3. Hit Save configuration
  4. Go to URL aliasesPATTERNS (admin/config/search/path/patterns)
  5. Under TAXONOMY TERM PATHS, for Pattern for all [desired vocabulary] paths enter [term:parents:join:/]/[term:name]
  6. Hit Save configuration and you are done!
  7. Now if you already have terms, just go to URL aliasesDELETE ALIASES (admin/config/search/path/delete_bulk) and then to URL aliasesBULK UPDATE (admin/config/search/path/update_bulk)

Here to help.

whitingx’s picture

Just wanted to thank you for adding this detailed solution, step 2 (setting slash to do not replace) worked perfectly for me.

ParkerDMartin’s picture

In greater detail, the node types that I am attempting to automatically alias have multiple term references from multiple taxonomies. I would like the option of selecting which taxonomy pathauto is utilizing. Is there any way to do this now?

In addition to this, could we also have the option to add [node:taxonomy-child] or something like it? I am frustrated that at the moment I can only select terms and vocabularies.

decibel.places’s picture

tried #1 but not a valid token

tried #6 but didn't change anything

duaelfr’s picture

@cesareaugusto

You can achieve this by using Entity API and its submodule entity_token like this :
[node:field_citta:parents:join-path]/[node:field_citta:name]/[node:title]

It will only work with the last dev version of pathauto

decibel.places’s picture

I solved it by creating a Computed Field and using that field as the path token containing the terms:

$tertid0 = $entity->field_service_category['und'][0]['tid'];
$tertid1 = $entity->field_service_category['und'][1]['tid'];
$term_load0 = taxonomy_term_load($tertid0);
$term_name0 = $term_load0->name;
$term_load1 = taxonomy_term_load($tertid1);
$term_name1 = $term_load1->name;
$entity_field[0]['value'] = $term_name0 . '/' . $term_name1;

In my case it was even more complex because the Hierarchical Taxonomy Select fields were conditional on another vocabulary, so I had to get that controller vocab term tid then create a switch to load the term tids from the dependent vocabulary - I don't think #10 would work

$proptid = $entity->field_service_property['und'][0]['tid'];

switch ($proptid){
case 89:
$tertid0 = $entity->field_service_category_1['und'][0]['tid'];
$tertid1 = $entity->field_service_category_1['und'][1]['tid'];
break;
case 90:
$tertid0 = $entity->field_service_category_2['und'][0]['tid'];
$tertid1 = $entity->field_service_category_2['und'][1]['tid'];
break;
case 91:
$tertid0 = $entity->field_service_category_3['und'][0]['tid'];
$tertid1 = $entity->field_service_category_3['und'][1]['tid'];
break;
case 92:
$tertid0 = $entity->field_service_category_4['und'][0]['tid'];
$tertid1 = $entity->field_service_category_4['und'][1]['tid'];
break;
case 93:
$tertid0 = $entity->field_service_category_5['und'][0]['tid'];
$tertid1 = $entity->field_service_category_5['und'][1]['tid'];
break;
default:
}

$term_load0 = taxonomy_term_load($tertid0);
$term_name0 = $term_load0->name;
$term_load1 = taxonomy_term_load($tertid1);
$term_name1 = $term_load1->name;

$entity_field[0]['value'] = $term_name0 . '/' . $term_name1;

Then I can simply insert the value of the computed field - with the "/" (make sure you are not replacing that punctuation character in your alias settings)

manuel garcia’s picture

Status: Active » Closed (works as designed)

There's no need for pathauto to replicate this functionality.

With latest stable versions of both entity and pathauto, you can enable entity_token: drush en entity_token -y, and then use the new tokens available for you, like [node:field-FIELDNAME:parents:join-path].

Entity token module also provides a lot of other tokens, imho more than enough.

saratt’s picture

The new token works great when the widget type is Select for the taxonomy select, but not when the type is hierarchical select. Is there anyway i can get the entire hierarchy(paret/child/grand-child/page-title) in the URL when using hierarchical select.

Thanks.

manuel garcia’s picture

@st455 you may want to cross post in hierarchical select issue queue, it might be their problem perhaps.

zmove’s picture

Subscribing to this issue.

I'm not sure this issue would be related to modules that provides other taxonomy widgets.

The possibility to defined taxonmy in a hierarchical was is a core function. That's also a core function to be able to select multiple terms for one node. Hierarchical select, Taxonomy term tree widget and all module like that doesn't change this fact, they just change the way it's displayed.

So it's probably the job of pathauto, token and entity token to make possible to create hierarchical path based on hierarchical taxonomy (not the module, the fact to have parents and children terms).

velvetpixel’s picture

Issue summary: View changes

using parents throws an error:
"The Pattern for all Basic page paths is using the following invalid tokens: [node:field_taxi:parents:join-path]."

field_taxi is my term reference machine name for basic page content type.

here is the full pattern I tried for the basic page path that trows the above error:
[node:field_taxi:parents:join-path]/[node:title]

This works:
[node:field_taxi]/[node:title]

But only provides the url path for the term the page is associated with and doesn't add the nested parent terms to the url :(

I have the following modules enabled:
Entity API 7.x-1.3
Entity tokens 7.x-1.3
Pathauto 7.x-1.2

Does this require the dev version of path auto to recognize that token syntax?