If parent term url wasn't autogenerated. And children term url was generated using token [term:parents:join-path], it use wrong parent category url (autogenerated, but not real).

Imagint we have set Blog taxonomy terms URL aliases generation rule to be [term:parents:join-path]/[term:name]

And we have categories structure: "Parent Category" with URL "my-parent-category" filled by hands.

"Sub Category" we will get URL"parent-category/sub-category" but not "my-parent-category/sub-category".

So if you filled some parent category URL by hands, you would have to update each subcategory URL and nodes URLs as well (if your node URL structure use full path throw the terms)
http://stackoverflow.com/questions/24998797/drupal-pathauto-token-termpa...

Comments

Dave Reid’s picture

Status: Needs review » Closed (works as designed)

[term:parents:*] defaults to all the names of all the parent terms. You are wanting the actual URL alias of the parent term itself, not all parents, which is a different token: [term:parent:url:path] I believe.

pshlykov’s picture

All the parents, but real aliases, not generated again for each posts and subcategory parent using it's name. When generating sub-category link parent links generated from parent category names, and they need to be generated using real parent category URL, if user makes his parent cat link "changed-cat" instead of "cat", he wants so subcategories were using that link not "cat" but "changed-cat". I think it's logic bug in that token.

Dave Reid’s picture

Pathauto has the capability to auto-alias all children terms of a parent term (see http://cgit.drupalcode.org/pathauto/tree/pathauto.module#n707) but it is disabled by default because it could *very easily* cripple sites with large amounts of taxonomy terms in a hierarchical vocabulary. If you need to re-alias all terms, I would suggest writing an update hook to regenerate all the child term aliases using Pathauto.

pshlykov’s picture

No, let's imagine we have filled parent cat url by hands, and only after that we will create subcategories. That token will use generated parent URL, not that one we have provided. I understand that it won't regenerate subcategories that already present. That is another thing.

Dave Reid’s picture

The token uses whatever URL alias that term has, whether it was generated by Pathauto, or set manually. Please give it a try.

pshlykov’s picture

Are you talking about [term:parents:join-path], are you sure? (i was trying yesterday, and after that i have created that question) I don't need [term:parent:url:path] because i need URL including all term parents, as i wrote, not only direct one parent.

Dave Reid’s picture

[term:parents:join-path] will not give you the expected result you are looking for if you have set a parent term's URL alias manually. This is why I recommended in comment #1 to use [term:parent:url:path].

Think about this for a little bit here. Let's say your taxonomy term pattern in [term:parent:url:path]/[term:name].

  1. Create a new root term 'Root' with a manual alias of root-term.
  2. Create a child term of 'Root' named 'First Child.' Pathauto would generate this term's alias as root-term/first-child.
  3. Create a child term of 'First Child' named 'Second Child.' Pathauto would generate this term's alias as root-term/first-child/second-child.
MacSim’s picture

Sorry to dig up that old issue but I do agree with pshlykov.
That token is not working as expected even in Drupal 8!
I am gonna use what Dave Reid said in #7 but I was expecting that [term:parents:join-path] token to build the correct path using the parents URL alias whether or not it was manually created...
Either the description of the token is wrong or it's just not working as expected.
Anyway there's something to do here.

MacSim’s picture

Status: Closed (works as designed) » Needs work
Berdir’s picture

Status: Needs work » Closed (works as designed)

No, it is working exactly as defined.

I think the path in join-path is confusing you. That just means that it combines together the list of values that it receives with a "/", it is *not* the path of the parents. :parents gives you internally a list of all the parent *names*, then that's combined into a string with /.

MacSim’s picture

Status: Closed (works as designed) » Needs work

Yep it is confusing ! I guess the name of the token is not good. When I read "join-path" I am not expecting it to work as a "join-name"
And I think we should definitively have a token giving that [term:parent:url:path]/[term:name] value.

MacSim’s picture

Status: Needs work » Closed (works as designed)

Sorry I didn't reloaded the page before to submit the form again

websiteworkspace’s picture

The following token set will generate the full URL that the original poster was looking for:

[term:vocabulary]/[term:parents:join-path]/[term:name]

Each of these tokens works as defined and expected.

The original poster didn't seem to know about the existence of [term:vocabulary] to provide the top level of the URL.

websiteworkspace’s picture

@ Dave Reid

There isn't any such token as the following token:

[term:parent:url:path]

The complete set of available tokens can be perused at

{site}/admin/help/token

on any D7 or D8 site.

The workable solution on both D8 and D7 is:

[term:vocabulary]/[term:parents:join-path]/[term:name]

or

[term:vocabulary:name]/[term:parents:join-path]/[term:name]

--
Parenthetically, D8.x does not implement as much functionality for taxonomy tokens as exists in D7.x.

One of the important features that is mission is functionality similar to the above, when using a reference field from within a node.

For example the following token construct exists and works in D7, to produce a complete URL to a node with a URL in a hierarchy of node/content categories:

[node:field-taxonomy-content-category:vocabulary]/[node:field-taxonomy-content-category:parents:join-path]/[node:field-taxonomy-content-category:name]/[node:title]

However, the following token type, with the - parents:join-path - construct, is missing in D8, which is a serious problem.
It is a seriously troublesome D8 feature omission.

[node:field-taxonomy(insert-name):parents:join-path]

Chris Charlton’s picture

I've seen `parents:join-path`.

posmishka’s picture

Hi,
I've found these patterns working for Drupal 8

[term:parents:join-path]/[term:name] Taxonomy term
[node:field_category:0:entity:url:path]/[node:title] Content

It was strange that only standart field_category appeared in path.
The custom field_news_category created for custom content type (but linked to the same taxonomy) didn't worked.

JioJio’s picture

#13 worked for me.

Thanks

alejo-moreno’s picture

@macsim you can get your expected result by creating two patterns:

First pattern for taxonomy terms: [term:parents:join-path]/[term:name]
Second pattern for content: [node:{name_of_the_field_taxonomy_term}:entity:url:path]/[node:title]

Remember to check "Generate automatic URL alias" for taxonomy term

nravens’s picture

In Drupal 9, I created a Taxonomy Term pattern [term:parents:join-path]/[term:name] but it doesn't create the full URL string beyond two terms.

I don't want to include the vocabulary in the string. The token pattern I mentioned does this:
parent/child1

If there's a child2 it does this:
child1/child2

What I want is parent/child1/child2

If I use [term:parents]/[term:name] it does this:
parent-child1/child2

Is this a bug or am I doing something wrong?