We have a bunch of term tokens in D6 token for the taxonomy term of a node that has the lowest weight vocabulary and lowest term weight. We should just make [node:term] a chainable token.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave Reid’s picture

Any ideas on the name of this token? Ideas are:
[node:term]
[node:lowest-term] (lowest weight = top)
[node:top-term]

DamienMcKenna’s picture

In the interest of KISS and convention over configuration, I think [node:term] would be a handy shortcut for the first term.

greggles’s picture

I like "top" or "lightest-term" since weights are described as "heavy" and "light" (at least I describe them like that).

DamienMcKenna’s picture

If the intention is to make it chainable, maybe [node:term-next] or [node:next-term] so that it is more logically chained out: [node:term-next]/[node:term-next]/[node:term-next]/[node:title]

Dave Reid’s picture

What I meant by making it chainable is that we can use things like [node:term:name] or [node:term:vocabulary:name].

DamienMcKenna’s picture

Ah, righteeo. So what would you get just doing [node:term], the $term->name value?

Dave Reid’s picture

Yep that defaults to the term name.

Dave Reid’s picture

Come vote on http://twtpoll.com/8y4lke ! :)

Dave Reid’s picture

Status: Active » Postponed

I don't think we should actually proceed with this. Marking as postponed for now.

xjm’s picture

Tracking. What was the reason not to proceed?

Dave Reid’s picture

Because D7 has no concept of taxonomies for nodes. They're fields and each vocabulary is a separate field. There is no concept of a top 'term' for a node.

xjm’s picture

I suppose it's sort of a duplicate of #691078: Field tokens. Assuming the field token takes the first entry in a field, that would sort of be the equivalent of the lightest term, and more configurable to boot. It wouldn't work across multiple vocabularies, but that's a feature that's more of a hindrance in D5 and D6, I think.

beckyjohnson’s picture

Are there really tokens for lower terms provided by the token module? I need this feature and I'm not sure what to do. I need to be able to show a token of a lower taxonomy term in my breadcrumbs.

Becky

Edit: Sorry I misunderstood. Top terms have low weights and vice versa. What I'm trying to research is how to get terms from other vocabularies into tokens and I misread what was discussed above.

artatac’s picture

The Pattern for all Article paths is using the following invalid tokens: [node:term].

Doesn't currently work in d7beta

Further background
Pattern for all Story paths:
[termpath-raw]/[title-raw]
In D7 beta with your latest dev 'term' is not mentioned in any of the replacement patterns. I tried
Pattern for all Article paths
[term:path]/[node:title]

but got the following error - The Pattern for all Article paths is using the following invalid tokens: [term:path].

Dave Reid’s picture

Yes because the token does not exist. Please read the issue.

artatac’s picture

Category: task » feature

apols - but in that case could I request that the d6 [termpath-raw] be made available in d7 or is there a workaround/different way of achieving this?

MondayNgt’s picture

I second the addition of a term path, as it was in Drupal 6 pathauto and still don't understand why it's not in D7. I have a client website which uses taxonomy for categories/subcategories for articles and generates the URL accordingly for SEO (for example, /electronics/computers/how-to-reformat-your-machine). I was looking forward to using D7 for the next major version of that site, but this is a showstopper.

Dave Reid’s picture

Status: Postponed » Needs review
FileSize
5.52 KB

Patch to add a [node:term] token for D7 with tests.

artatac’s picture

I downloaded the latest dev of token and this patch then using terminal on the mac ran the patch with only partial sucess see below


unknown-00-1f-5b-f8-5e-21:token joe$ patch < 741914-token-node-term-D7.patch
patching file token.tokens.inc
Hunk #1 succeeded at 113 with fuzz 2 (offset 49 lines).
Hunk #2 succeeded at 301 with fuzz 2 (offset 62 lines).
Hunk #3 succeeded at 308 with fuzz 2 (offset 54 lines).
Hunk #4 succeeded at 502 with fuzz 2 (offset -242 lines).
patching file token.test
Hunk #1 FAILED at 150.
Hunk #2 FAILED at 172.
Hunk #3 FAILED at 191.
Hunk #4 succeeded at 242 with fuzz 1 (offset -91 lines).
3 out of 4 hunks FAILED -- saving rejects to file token.test.rej

please advise

artatac’s picture

Bump

artatac’s picture

if this is still an issue contact me direct as I have a solution

Regards

Joe

amfis’s picture

please, post solution here.

Dig1’s picture

Similar to #16 and #17, I think D6 taxonomy is great and Pathauto for D6 really helps create Node URLs based on Vocabulary, Term, Sub-Term.

At the moment I can't see how to do that in D7 because the Replacement Patterns for Node Paths don't include Taxonomy terms...

Using Taxonomy for URL Replacement patterns is such a neat feature...it is not yet in D7 or am I missing something?

Thanks

frank31’s picture

Subscribing

artatac’s picture

I had to pay a coder to make this work. I was hoping a few of us could share the cost.
Like many I am happy to contribute my time back to the community but when I have to pay hard cash it is nice to get some help

Dave Reid’s picture

The patch is ready to test, not sure why you'd need to pay someone?

chronosinteractive’s picture

How long until there is a version with this patch included?

artatac’s picture

When I last tested the patch it failed and I got no response about the error. See above

chronosinteractive’s picture

What drupal version, and what token version did you test it on?

artatac’s picture

It is so long ago that it would be quicker to ask you what versions you are finding success with. I will happily redraft and use the latest d7 dev version of each of the modules needed

Dig1’s picture

SUCCESS :). Well guys, while attending the London D7 Launch party I remembered what a great community Drupal is...and today I woke up and 'smelt the coffee'...so first thing I did was research how to apply a patch...I studied Addison Berry's video and read the Drupal Manual.

Then I applied the patch that David provided in #18 and it installed first time using the Token Module directory for root:
patching file token.tokens.inc
Hunk #1 succeeded at 74 (offset 10 lines).
Hunk #2 succeeded at 294 (offset 55 lines).
Hunk #3 succeeded at 312 with fuzz 2 (offset 58 lines).
Hunk #4 succeeded at 875 (offset 131 lines).
patching file token.test
Hunk #1 succeeded at 215 (offset 65 lines).
Hunk #2 succeeded at 240 (offset 68 lines).
Hunk #3 succeeded at 262 (offset 71 lines).
Hunk #4 succeeded at 415 (offset 82 lines).

Then I got really excited when I saw that David had provided the facility for:
'First taxonomy term [node:term] The lowest-weighted taxonomy term associated with the node from the lowest-weighted vocabulary.'

My setup is:
Drupal 7.0, LAMP.
Pathauto 7.x-1.x-dev (2011-Jan-07)
Token 7.x-1.x-dev (2011-Jan-10)

And currently I am happily using:
Pattern for all Reference paths = [node:term:parent]/[node:term:name]/[node:title]

This is brilliant and Dave needs to be praised for his excellent work for the community :)

Thank you Dave

Digby

artatac’s picture

I can confirm that this is working well under Xampp on a windows 7 local host. I am impressed with the range of options but am struggling to find one that does the same as termpath.
I am using [node:term:parent]/[node:term]/[node:title]
which achieves the same as long as the term is only 2 tier eg
vegetables
-potatoes

but would not work if it was
vegetables
-potatoes
--king Edwards

Perhaps I am not looking well enough - but well done for this important contribution

MrSasquatch’s picture

I cannot get this to work. I replaced my token and pathauto modules with the same versions you're using...

Pathauto 7.x-1.x-dev (2011-Jan-07)
Token 7.x-1.x-dev (2011-Jan-10)

...and then I...

• Deleted all my existing aliases
• Made sure the taxonomy vocabulary I want to use to generate my URLs is the lowest weighted and populated with terms
• Made sure that taxonomy vocabulary is attached to my basic page content type as a required field

Now, when I go into the Pathauto "Patterns" configuration, I see a whole bunch of new built-in replacement patterns that I can use, but I still don't see the ones you're using, like [node:term:parent] and [node:term:name].

Basically I have a "departments" vocabulary attached to my basic page content type as a required field, and I want to structure my URLs like this...

/[DEPARTMENT VALUE]/[node:title]

It's the [DEPARTMENT VALUE] that I don't know how to add to the URL as a replacement pattern. For example, if a particular basic page has the "department" taxonomy vocabulary set to "shirts" and if the name of the page is "Blue Shirt" then I want the page to have a URL like...

/shirts/blue-shirt

What am I missing? Please help. And thank you so much in advance for any help that anyone can provide.

Thanks,
TheSasquatch

Dave Reid’s picture

After you apply the patch, you have to ensure you clear your caches (usually just by running the update.php script even if there were no database updates to run).

MrSasquatch’s picture

I didn't apply any patches. I just removed token and pathauto and re-added them using the recommended versions. Is that all I need to do? ...or is there also a "patch" that I also have to apply? Please advise, and thank you for your help!!! - TheSasquatch

Dave Reid’s picture

As this issue is still 'needs review' it means the patch has not been committed to the Token module yet, so yes, you'll need to still apply the patch yourself in the meantime.

MrSasquatch’s picture

I ran update.php, and it did apply some updates pertaining to Pathauto, but I still don't see the taxonomy/term-related replacement patterns showing up in the list, and when I try to use the ones shown in the example, I get an error. Any thoughts? Thanks for your help!!! - TheSasquatch

Dave Reid’s picture

"As this issue is still 'needs review' it means the patch has not been committed to the Token module yet, so yes, you'll need to still apply the patch yourself in the meantime."

MrSasquatch’s picture

Ah, I see. Thanks! Any idea how long it will be before the patch has been committed to the Token module?

willhowlett’s picture

If you can't wait you'll be able to patch the module manually yourself, instructions here: http://drupal.org/node/534548

The patch -> http://drupal.org/files/issues/741914-token-node-term-D7.patch might look a bit intimidating, but it's essentially just a case of adding the lines that begin with +, and removing lines begining with -, to the relevant files at the correct line.

artatac’s picture

could I ask what the equivalent of the D6 [termpath-raw] in this D7 version please

Thanks

Joe

dominateyourmarket’s picture

subscribe

shelleyp’s picture

I have a fairly flat taxonomy, and my paths in D6 consisted of vocabulary name/term name/story title.

Once I updated to the development versions of both token and pathauto, and applied the above patch, I was able to re-create the path using:

[node:term:vocabulary:name]/[node:term:name]/[node:title]

After a very frustrating day yesterday just trying to figure out what the problem was, I can happily say that this worked and I now have the same paths I had under D6.

MANY appreciations (let me repeat...MANY appreciations) to Dave Reid, both for the patch, and for helping me understand what broke between D6 and D7.

Once this is incorporated, the only other addition I would recommend is a file that shows a mapping between the previous patterns and the new one. This should probably be in the pathauto install. Perhaps even something in the config page, itself.

benanderson’s picture

Big thanks to Dave Reid for his work on this! I applied the patch from #18 above and had an almost identical setup as #31. Everything "just worked".

Many thanks,
Ben

Lars Jansen’s picture

With many thanks to Dig1 I now also have the patch David provided in #18 working for me.

My setup is:
Drupal 7.0, LAMP.
Pathauto 7.x-1.x-dev (2011-Jan-07)
Token 7.x-1.x-dev (2011-Jan-10)

node:term ROCKS!

Dave Reid’s picture

Status: Needs review » Needs work

I just realized that the {taxonomy_index} table is only maintained for published nodes only, and not for unpublished nodes, so this requires a different approach that won't cause this token value to go empty after a node is unpublished.

N20’s picture

worked like a charm! many thanks for that patch

Scott J’s picture

Thank you, thank you. Works for me too.

Drupal is working like a cMs once more.

anavarre’s picture

Subscribe

nigg1e’s picture

I couldn't get this patch to work. I kept getting the message below. This is the first patch I have ever done. Any ideas?

$ patch token.tokens.inc < termpatch.patch
(Stripping trailing CRs from patch.)
patching file token.tokens.inc
Hunk #1 succeeded at 74 (offset 10 lines).
Hunk #2 succeeded at 294 (offset 55 lines).
Hunk #3 succeeded at 312 with fuzz 2 (offset 58 lines).
Hunk #4 succeeded at 876 (offset 132 lines).
(Stripping trailing CRs from patch.)
can't find file to patch at input line 95
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|Index: token.test
|===================================================================
|RCS file: /cvs/drupal-contrib/contributions/modules/token/token.test,v
|retrieving revision 1.27
|diff -u -p -r1.27 token.test
|--- token.test 16 Nov 2010 03:12:10 -0000 1.27
|+++ token.test 16 Nov 2010 04:14:59 -0000
--------------------------
File to patch:

nigg1e’s picture

I have just managed to get the patch to work. I think I was using a slightly newer version of token. However, now my site isn't functioning. There are still no options in path auto for me to pick a taxonomy term in the token drop down and also I cant get into my configurations menu! I get this error message every time I try:

Fatal error: require_once() [function.require]: Failed opening required 'C:\wamp\www\drupal7/sites/all/modules/token/token.tokens.inc' (include_path='.;C:\php\pear') in C:\wamp\www\drupal7\includes\module.inc on line 300
Call Stack
# Time Memory Function Location
1 0.0004 674968 {main}( ) ..\index.php:0
2 0.2470 28531944 menu_execute_active_handler( ) ..\index.php:22
3 0.2544 29749144 call_user_func_array ( ) ..\menu.inc:501
4 0.2544 29749384 system_admin_config_page( ) ..\menu.inc:0
5 0.2544 29749432 system_status( ) ..\system.admin.inc:14
6 0.2993 32807136 module_invoke_all( ) ..\system.admin.inc:2237
7 0.3179 33500520 call_user_func_array ( ) ..\module.inc:817
8 0.3179 33500840 token_requirements( ) ..\module.inc:0
9 0.3179 33501128 token_find_duplicate_tokens( ) ..\token.install:13
10 0.3179 33501416 module_implements( ) ..\token.module:779
11 0.3242 33902744 module_load_include( ) ..\module.inc:675

Scott J’s picture

FileSize
31.72 KB

niggle,
Here's one I prepared earlier...

I just edited this version http://drupal.org/node/734592 by hand, and it's working for me.

effulgentsia’s picture

Subscribe. I didn't follow the full discussion since #9, but what value does this have that isn't captured in #691078: Field tokens? Given that in D7, taxonomy is just a field, what's the point of adding another special case token name on top of the one we'll get from that issue?

Scott J’s picture

re: #53
The value is in not needing to know in advance what the field names are.

For example, I want to set up the tokens in pathauto and then forget about it. I don't want to have to revisit admin/config/search/path/patterns every time that I add a new vocabulary, content type and/or field. That would rather take the 'auto' out of pathauto.

nigg1e’s picture

Scott J,

Nice one! This works for me. Still not sure why the version I patched resulted in all the errors when I tried to navigate to the configuration area.

Using Pathauto 7.x-1.0-beta1

Anyway, thanks again.

MrSasquatch’s picture

So do I still need the patch to get taxonomy term working in Pathauto, or is this rolled into a dev or alpha or beta by now? Please advise, and thank you so much for assistance.

- TheSasquatch

N20’s picture

By the way, you have to create a new node to see the patch working. in my case the url didnt updated properly with the bulkupdate from autopath.

5ulo’s picture

I have latest pathauto (7.x-1.x-dev) and token (7.x-1.x-dev) installed and i don't see the token [node:term], so it's still not fixed :(

MrSasquatch’s picture

So hard to wait.

N20’s picture

you dont see them under "replacement patterns" listed. just use them. if the patch works for you, you dont get any errors using [node:term]

Scott J’s picture

Sulo, and TheSasquatch,

I have posted a fully patched working version at #52 and [node:term] does show up under replacement patterns -> nodes, so please just try it.

Don't forget to visit admin/config/development/performance and "Clear all caches" after you have installed it.

MrSasquatch’s picture

I trust it works. I don't doubt the patch works. But a patch is not useful to me. We need modules that work as-is because of the constraints of our project. It's a big enough stretch that we're using beta and dev modules. So I'm going to have to wait until a new dev or beta comes out that includes the patch. Any idea when that will be?

effulgentsia’s picture

So I'm going to have to wait until a new dev or beta comes out that includes the patch. Any idea when that will be?

The last status change on this issue was in comment #46, where one of the project maintainers responded that the latest patch still needs work, and why. So, unless he changes his mind, it won't be committed to CVS, and therefore, won't be part of a dev snapshot or the next beta release, until someone posts an updated patch that addresses that concern, and the new patch has been adequately reviewed.

Maybe Dave Reid himself will have time to work on that this week. Maybe not. It's usually hard to make predictions of when problems will get solved when it's being worked on in volunteer time. If your project constrains you to not using patches representing in-progress solutions, but only fully worked out solutions that have been incorporated into a release, then I suggest you (or your organization) try to hire someone who can drive this patch to completion. You may want to start by contacting the people who've already contributed on this issue (e.g., Dave Reid and Scott J) to see if they have availability or know someone who does.

willhowlett’s picture

TheSasquatch - if this is for clients personally I would stick to Drupal 6 for the time being. That's the approach my company are taking. We're keeping a close eye on the development of the D7 versions of modules we need working, and we won't consider building sites for clients in D7 until all the features we need are in place. In the meantime D6 is still doing the job for us fantastically.

elachlan’s picture

Subscribing.

#46 - Is there a way to add unpublished nodes to the index? What is the main reason they were removed?

Dig1’s picture

UPDATE

Just to let you know that I just setup Drupal with:

- Drupal core 7.0 LAMP
- Pathauto 7.x-1.x-dev (2011-Jan-28)
- Token 7.x-1.x-dev (2011-Feb-01)

and then applied the patch from #18 above to the token module and it worked fine.

Cheers

Dig

elachlan’s picture

What about a middle ground, [node:active:term]. So that its only published nodes. Not sure what to do in the case of an unpublished node though. Maybe have a safe default.

Otherwise you will have to change the taxonomy system or seed unpublished node taxonomy data into your own table.

elachlan’s picture

Stumbled across this issue, thought it might help.

http://drupal.org/node/962664

Apparently unpublished nodes DO have Taxonomy data, but you can not get it by name? (that's my understanding of it, I could be wrong).

daviesap’s picture

+1

smbell’s picture

subscribe

mikejonesok’s picture

Is there going be an official release soon? I keep getting a message to update token. Thanks for the patch!

kumkum29’s picture

Hello,

After editing the file token.tokens.inc I get a blank page for the site configuration. The patch does not work. (after update.php and clear cache)
Can you tell me why or you can make available the new file token.tokens.inc.

Thank you.

- Drupal core 7.0
- Pathauto 7.x-1.x-dev (2011-Jan-28)
- Token 7.x-1.x-dev (2011-Feb-25)

kumkum29’s picture

it's ok for the patch ;)

sebish’s picture

Subscribe

awasson’s picture

Subscribe

Thanks to Dave Reid for the patch on #18. It worked like a charm : )

RavenHursT’s picture

Patch in #18 works GREAT... Thanks!!! Why in the world hasn't this been checked into HEAD yet?!?!

elachlan’s picture

See #46 apparently unpublished nodes do not have taxonomy entries.

http://drupal.org/node/962664 might be useful in solving this.

georgedamonkey’s picture

subscribe

Dave Reid’s picture

Yes #962664: Taxonomy Index for unpublished entities would definitely make me feel better about committing this 'easy' token for people since proper field tokens is much harder.

tarheeldev’s picture

subscribe

Dave Reid’s picture

I can work around this for now by inserting these values into the table myself, but I'm not sure what repercussions there would be with other modules.

vivefree’s picture

Status: Closed (won't fix) » Needs review

#18: 741914-token-node-term-D7.patch queued for re-testing.

wernercd’s picture

Status: Needs work » Needs review

Hand edited token.tokens.inc. Works fine so far. Please push to module soon... I dont' wanna be scurd of patching :/

inversed’s picture

subscribe

jviitamaki’s picture

sub

framewerx’s picture

subscribe

Status: Needs review » Needs work

The last submitted patch, 741914-token-node-term-D7.patch, failed testing.

EJvL’s picture

I also expected this to be part of the main Token module. Until that happens, you can consider using the Entity tokens module, provided as part of the Entity API module. See also #1155512: Using Taxonomy term tokens. This solved my problems...

(D6 note: in D6, similar functionality was provided by the Taxonomy token module)

creatile’s picture

Hi
I am working on Drupal 7
I need to add a taxonomy term for a content type in custom breadcrumbs and pathauto with the following pattern:
taxonomy parent / taxonomy term / node title.

How can I do that ? do I need the term:node feature that you request ?

melonkernel’s picture

subscribe

ILLIA’s picture

subscribe

creatile’s picture

I found that I could use taxonomy terms in custom breadcrumbs and pathauto like this:

[node:field_name_of_field:name] for term
or
[node:field_name_of_field:parent] for parent term
or
[node:field_name_of_field:name:url:alias] for url alias of a term

These are already available as tokens

andrenoronha’s picture

Subscribe!

elachlan’s picture

@#92 - What version of Drupal are you using? I cannot use these terms in content paths.

andrenoronha’s picture

@#94 @#92 Neither could I!

sebish’s picture

#92 works perfectly well. Thanks Creatile. No need of using [node:term] anymore and I can finally update the token module without patching it everytime. For info, I'm using drupal 7.2, Token 7.x-1.0-beta2, Entity API 7.x-1.0-beta8.

andrenoronha’s picture

I'm using the same versions but without success.

I got the message: The Pattern for all .... paths is using the following invalid tokens: [node:field_canal:name].

same with [node:field_field_canal:name].

it's a term field.

ILLIA’s picture

Hey, if it helps someone to create custom URL aliases using taxonomy terms you can check out my comment at http://drupal.org/node/1044980 on June 6.

andrenoronha’s picture

@98 thank you!! now i got it right.

it's not field_name_of_the_field
it's field-name_of_the_field

and it's seachable at the replace patterns below the url config form.

:)

creatile’s picture

You are right I made a mistake. So the right way is
[node:field-name-of-field:name] for term
or
[node:field-name-of-field:parent] for parent term
or
[node:field-name-of-field:name:url:alias] for url alias of a term

You can find them as token pattern replacement

scott.whittaker’s picture

subscribe

Dig1’s picture

Call me simple...but I am not sure what the problem is...all I am looking for is the ability to create node URLs from taxonomy terms and node title. The patch in #18 gives me that.

FYI (as per #31 and #66) I have been using it for a while with different builds of the Token module, it seems to work fine for me. Surprisingly it used to be marked as working and now it has changed to not working for some reason...anyway I just patched again today and everything continues :)

I am using: Drupal 7.2, Administration menu 7.x-3.0-rc1, Pathauto 7.x-1.0-rc2, Taxonomy Manager 7.x-1.x-dev (2011-Mar-25), Token 7.x-1.x-dev (2011-Jun-12).

patching file token.tokens.inc
Hunk #1 succeeded at 86 (offset 22 lines).
Hunk #2 succeeded at 383 (offset 144 lines).
Hunk #3 succeeded at 401 with fuzz 2 (offset 147 lines).
Hunk #4 succeeded at 1143 (offset 399 lines).
patching file token.test
Hunk #1 succeeded at 277 (offset 127 lines).
Hunk #2 succeeded at 302 with fuzz 2 (offset 130 lines).
Hunk #3 succeeded at 324 with fuzz 2 (offset 133 lines).
Hunk #4 succeeded at 477 with fuzz 1 (offset 144 lines).

Cheers

Dig

luco’s picture

subs. :]

truls1502’s picture

subscribe

kevinquillen’s picture

The patch from #18 will not apply for me.

awasson’s picture

I used the patch in #18 and it did work however whenever you update the module you have to repatch so instead I followed the instructions for using Entity API in #98 and it worked perfectly. No more patching.

phpleb’s picture

Status: Needs work » Needs review

#18: 741914-token-node-term-D7.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 741914-token-node-term-D7.patch, failed testing.

Dig1’s picture

Yes, I reckon entity api is the way to go...

Well I finally got a bit fed-up with patching Token each time a new version released.

So I thought I'd swallow my reservations about looking at yet another module and decided to investigate this 'entity stuff'. http://www.istos.it/blog/drupal/drupal-entities-part-1-moving-beyond-nodes is a great post.

So I figured I'd install the entity module and then found to my surprise that it was already installed and enabled (VBO needs it...that must have just slipped by me :o)

So I looked for replacement patterns and there staring at me was [node:field-tags:name]. I replaced [node:term] with [node:field-tags:name] and everything in the garden is now rosy. Quelle surprise!

Dig

artatac’s picture

I have entity api and entity tokens enabled but when I go to /admin/config/search/path/patterns > Pattern for all Article paths and add [node:field-tags:name]/[node:title] I get an error
[The Pattern for all Article paths is using the following invalid tokens: [node:field-tags:name].]

Is there another step needed please

hynnot’s picture

The same of artatac.
Suscribe +1

Dig1’s picture

#110 OK, it depends on the name of the taxonomy vocabulary you have installed. I reckon the best thing for you to do is go to admin/config/search/path/patterns and then click on the 'Replacement Patterns' to see what the system is making available to you...

Look at the Nodes section and you should find your taxonomy stuff in there. Maybe your taxonomy vocabulary is not called 'tags' but something else...

Post back how it goes. Cheers.

artatac’s picture

FileSize
41.26 KB

That is the point - despite using all the latest dev releases, I never get any taxonomy path settings at all. See attached screen shot.

Dig1’s picture

Hmm, dunno if this is the place to discuss this issue...but lets check the basics. D7 comes with tags as the default empty vocabulary. Questions:

1) Have you added terms to that, or any, vocabulary?
2) Do your content types have a term-reference field that uses that, or any, vocabulary?
3) have you created nodes that contain vocabulary terms in term-reference fields?

artatac’s picture

using the default vocab
yes have added terms
yes terms have been used in articles

just a thought - do you have to limit terms to i or can they be unlimited?

Karol Haltenberger’s picture

Is your taxonomy field multi-value?
The tokens do not get generated for those.

artatac’s picture

That was the issue - thanks for your feedback. Now I have set tags field to have only 1 value and have set the pattern to

[node:field-tags:parent:root:name]/[node:field-tags:parent:name]/[node:field-tags]/[node:title]

I get the url I need eg

http://localhost/acquia02/fruit/orange/jamaican-orange/jamaican-orange32

Shame there is not a single term like term-path rather than have to use three terms

droplet’s picture

Suscribe +1

Dig1’s picture

#117 so Joe it looks like you are finally sorted...have yourself a beer :)

georgedamonkey’s picture

Wow... thank you so much Dig1, Entity worked fantastic!

sharifudinrizal’s picture

#117 works fine, as long as the term is no more than 3 levels deep.

e.g.
term 1 (root)
- term 2 (parent)
-- term 3 (term)

So it becomes /term-1/term-2/term-3/title

If we place the node in the 4th level down, it breaks:

term 1 (root)
- term 2 (parent?)
-- term 3 (parent)
--- term 4 (term)

We'll get /term-1/term-3/term-4/title.

term 2 is skipped, because it's not the current parent of the term.

Am I correct in this analysis?

Dave Reid’s picture

Status: Needs work » Closed (won't fix)

Basic field tokens are now available in 7.x-1.0-beta4. Eventually you should be able to use more detailed tokens as part 2 of the effort with #691078: Field tokens.

But basically since terms are now fields, aside from supporting them in field tokens, we are not adding a [node:term] token. This is due to problems that the token needs to work in the same way if a node is unpublished or not - and this is not possible due to core's use of the {taxonomy_index} table.

Note that we did implement a [node:terms] token in http://drupal.org/project/taxonomy_entity_index.

vlacatocc’s picture

Status: Needs review » Closed (won't fix)

I've managed to get the urls for the products on my Drupal 7 webshop built up with their full taxonomy path, regardless of how many terms there are in the hierarchy. This solves the issue mentioned in post #121 where the hierarchy could only contain exactly 3 terms.

To get this to work, I've created a module that generates a few extra tokens which can be used with modules like pathauto or page_title. The module has dependencies to 'taxonomy', 'pathauto' and 'custom_breadcrumbs_taxonomy'.

The code is quite ugly for now as I only just got it working and I didn't have the time to clean it up yet.
Anyway, here goes:

tom.info:

name = Tom
description = This is Tom's personal module for custom code.
core = 7.x

dependencies[] = pathauto
dependencies[] = taxonomy
dependencies[] = custom_breadcrumbs_taxonomy

tom.module

<?php
/**
* @file
* A personal module that includes custom code.
*/

/**
 * Implements hook_token_info().
 */
function tom_token_info() {
	$info['tokens']['node']['term-path'] = array(
		'name' => t('Term path (for url)'),
		'description' => t('The full hierarchical path of the taxonomy the node belongs to (for urls).'),
	);
	$info['tokens']['node']['term-path-title'] = array(
		'name' => t('Term path (for page title)'),
		'description' => t('The full hierarchical path of the taxonomy the node belongs to (for page titles).'),
	);
	$info['tokens']['term']['term-path'] = array(
		'name' => t('Term path (for url)'),
		'description' => t('The full hierarchical path of the taxonomy term (for urls).'),
	);
	$info['tokens']['term']['term-path-title'] = array(
		'name' => t('Term path (for page title)'),
		'description' => t('The full hierarchical path of the taxonomy term (for page titles).'),
	);

	return $info;
}

/**
 * Implements hook_tokens().
 */
function tom_tokens($type, $tokens, array $data = array(), array $options = array()) {
	$url_options = array('absolute' => TRUE);
	if (isset($options['language'])) {
		$url_options['language'] = $options['language'];
		$language_code = $options['language']->language;
	}
	else {	
		$language_code = NULL;
	}
	$sanitize = !empty($options['sanitize']);

	$replacements = array();

	if ($type == 'node' && !empty($data['node'])) {
		$node = $data['node'];

		foreach ($tokens as $name => $original) {
			switch ($name) {
				case 'term-path':
					$replacements[$original] = tom_get_terms_hierarchy_for_node($node);
					break;
					
				case 'term-path-title':
					$replacements[$original] = tom_get_terms_hierarchy_for_node($node, ' | ', false, false, false, false);
					break;
			}
		}
	}

	elseif ($type == 'term' && !empty($data['term'])) {
		$term = $data['term'];

		foreach ($tokens as $name => $original) {
			switch ($name) {
				case 'term-path':
					$replacements[$original] = tom_get_terms_hierarchy_for_term($term);
					break;
					
				case 'term-path-title':
					$replacements[$original] = tom_get_terms_hierarchy_for_term($term, ' | ', false, false, false, false);
					break;
			}
		}
	}

	return $replacements;
}

function tom_get_terms_hierarchy_for_node($node, $separator = '/', $separator_at_start = false, $descending = true, $include_root = false, $clean = true) {
	module_load_include('inc', 'custom_breadcrumbs_taxonomy');
	module_load_include('inc', 'taxonomy');

	$terms = custom_breadcrumbs_taxonomy_node_get_terms($node);
	reset($terms);
	$first_tid = key($terms);
	
	return _tom_get_terms_hierarchy(taxonomy_get_parents_all($first_tid), $separator, $separator_at_start, $descending, $include_root, $clean);
}

function tom_get_terms_hierarchy_for_term($term, $separator = '/', $separator_at_start = false, $descending = true, $include_root = false, $clean = true) {
	module_load_include('inc', 'taxonomy');
		
	return _tom_get_terms_hierarchy(taxonomy_get_parents_all($term->tid), $separator, $separator_at_start, $descending, $include_root, $clean);
}

function _tom_get_terms_hierarchy($terms_hierarchy, $separator = '/', $separator_at_start = false, $descending = true, $include_root = false, $clean = true) {
	module_load_include('inc', 'pathauto');

	$terms_hierarchy_string = '';
	
	if ($descending) {
		for ($i = count($terms_hierarchy) - ($include_root ? 1 : 2); $i >= 0; $i--) {
			$terms_hierarchy_string .= $separator . ($clean ? pathauto_cleanstring($terms_hierarchy[$i]->name) : $terms_hierarchy[$i]->name);
		}
	}
	else {
		for ($i = 0; $i < count($terms_hierarchy) - ($include_root ? 0 : 1); $i++) {
			$terms_hierarchy_string .= $separator . ($clean ? pathauto_cleanstring($terms_hierarchy[$i]->name) : $terms_hierarchy[$i]->name);
		}
	}
	
	return $separator_at_start ? $terms_hierarchy_string : substr($terms_hierarchy_string, strlen($separator));
}
//omit closing php bracket! ?>

note: I'm omitting the root term in these examples because I'm using that as a means to differentiate the terms for different languages.
note 2: Again, I'm sorry for the ugly code. I need to make some time to clean it up. For now, I'm just happy I finally got this to work, after many months of breaking my head about this issue! ;)

This results in 4 additional tokens, 2 for the node pages and 2 for the term pages (both times one aimed for the page title and one aimed for the url).

In page title I now have the following tokens set:
Content Type - Product Display: [node:title] | [node:term-path-title] | [site:name]
Results in something like: 'My Product | Category A.1.2 | Category A.1 | Category A | Site name'
Vocabulary - Catalog: [term:term-path-title] | [site:name]
Results in something like: 'Category A.1.2 | Category A.1 | Category A | Site name'

In pathauto the equivalent tokens are:
Product display paths: [node:term-path]/[node:title]
Results in something like: '.../category-a/category-a-1/category-a-1-2/my-product'
Catalog paths: [term:term-path]
Results in something like: '.../category-a/category-a-1/category-a-1-2'

I hope this example can give people some ideas. :)

Oh yes, almost forgot... The module versions I'm using are:
Core: v7.8
Page Title: v7.x-2.5
Path Auto: v7.x-1.0-rc2
Custom Breadcrumbs: v7.x-2.x-dev (2011-Sep-06)

EDIT: On second thought, I could probably get away with removing the dependency to Custom Breadcrumbs. But I'm using that module anyways to achieve a similar behaviour as the one I want for the paths and the page titles, but for the breadcrumb instead (e.g. 'Home > Catalog > Category A > Category A.1 > Category A.1.2 > My Product').

jcamfield’s picture

To clarify "'First taxonomy term [node:term] The lowest-weighted taxonomy term associated with the node from the lowest-weighted vocabulary.'"

That pulls the topmost term in the global taxonomy term list from the bottom-most Taxonomy field on the content-type's Manage Fields (NOT display) -- not the highest/lowest weight.

I'd suggest it should take it from the first-listed vocab, but regardless, this is exactly the tool I was looking for for sane SEO paths from pathauto/token!

bancarddata’s picture

vlacatocc,

I have tried so many patches, modules, and token combinations and finally I come to something that just works as I need it to. Thank you so much for posting your solution! I am pretty sure it will only be needed temporarily, but how long "temporarily" will end up being is anyone's guess.

Thanks!

2pha’s picture

Thanks vlacatocc,
saved me a lot of time.

sabeeln’s picture

Status: Closed (won't fix) » Needs review

#18: 741914-token-node-term-D7.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 741914-token-node-term-D7.patch, failed testing.

The last submitted patch, 741914-token-node-term-D7.patch, failed testing.

roadie_jay’s picture

Hi.
Thanks very much for providing this module. I am trying to implement it on a d6 to d7 conversion. It works for the most part except that the parent terms are not included in the node's pathauto generated url. Any idea why this would be the case?

Solution found - the top level term is omitted from the url. I just added a single term below the root and made all the previous top level terms children of it. Paths look great now.

Dave Reid’s picture

Assigned: Dave Reid » Unassigned
klonos’s picture

@Dave Reid: Hey Dave, I'm coming from #691078: Field tokens that is related, but locked because it reached 500+ comments. Still there's no update there for some time and unfortunately there is no easy way to "follow" (as in subscribe) to g.d.o yet. So, can you please give us a status update?

Also, please unlock #691078: Field tokens. People that don't want to be annoyed by updates to that issue can easily unfollow. Alternatively, we could open a new issue, add the summary of #691078: Field tokens and point people from #691078: Field tokens to it. Thank you in advance for considering this one.

protools’s picture

internets’s picture

Hmm I've tried the patch in #18 and the token module supplied in #52.

The patch failed against the latest dev version of the token module. (7.x-1.x-dev Oct-1-2013)

patching file token.tokens.inc
Hunk #1 succeeded at 107 (offset 43 lines).
Hunk #2 succeeded at 433 (offset 194 lines).
Hunk #3 succeeded at 451 with fuzz 2 (offset 197 lines).
Hunk #4 succeeded at 1473 with fuzz 2 (offset 729 lines).
patching file token.tokens.inc
Hunk #1 FAILED at 150.
Hunk #2 FAILED at 169.
Hunk #3 FAILED at 185.
Hunk #4 FAILED at 325.
4 out of 4 hunks FAILED -- saving rejects to file token.tokens.inc.rej

Using the modules supplied in #52, installed module and cleared cache. Still did not see new replacement patterns.

I just want to recreate the Replacement Pattern functionality of [vocab-raw] and [term-raw] in Drupal 7. Are there any other solutions out there?

Dig1’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)

The Entity token module is part of the Entity package of modules, it provides lots of new tokens to use everywhere that tokens are currently available. It does this by being aware of the structure of fields on entities and exposing extra options for fields that reference entities. For example, it allows you to use many more tokens about taxonomy terms added to content. Read more at http://www.computerminds.co.uk/drupal-code/entity-token.

DamienMcKenna’s picture

Status: Closed (won't fix) » Needs work

Requiring the Entity module to display tokens for fields provided by core is a little silly.

SolasArd’s picture

Is there any solution for a similar problem in D6?