I've been using the newest code for the token module with the autotitle module to create node titles based on taxonomy terms so that I can then easily access the node using the views module. The problem I'm having is that when a user creates a new content page (in my case a content type called selectives) and assigns taxonomy terms to it, the title is not generated when I use the [term] token when you submit the content.
However, when you edit that page again one more time and submit it, it correctly titles the node based on the taxonomy term associated with it. I did some digging around in the database tables and it appears that on the first submit no title is being created. I wonder if this has something to do with the node not have a taxonomy term associated with it until you press submit and than when you click edit again it now recognizes the node taxonomy terms. I've tried it with other tokens like username and node id and they work fine so it must be something unique to way that taxonomy terms are generated and how the token module extracts that information from Drupal's execution path.
Any help in overcoming this problem would be much appreciated. I'm attaching a screen shot of what my problem looks like.
| Comment | File | Size | Author |
|---|---|---|---|
| #29 | token_node_tax_parsing_137669.patch | 1.93 KB | greggles |
| #24 | auto_nodetitle-get_taxonomy_working-137669-24.patch | 654 bytes | dmitrig01 |
| screenshots.JPG | 86.11 KB | c_philip |
Comments
Comment #1
gregglesWhen you say "newest" do you mean 5.x-1.6 (as you selected) or HEAD. I have a feeling that HEAD will fix this.
If not, we'll need more information (like what kind of taxonomy you are using that causes this problem).
Thanks.
Comment #2
J3 commentedYes, the issue occured on version 1.7. I have just tried it.
here are my steps.
1. set auto title as [term] for a node type
2. create a new node, select a term such as "abc"
3. save the node, the title is empty (wrong)
4. edit the node, don't change anything, save it again, the title is "abc" (correct).
Comment #3
gregglesWhat kind of taxonomy (taxonomies) are you using?
Single, multiple, required/optional, free tagging? Multiple taxnomies? etc.
Thanks.
Comment #4
J3 commentedI tested
1. Single, Multiple select
2. Single, Required
3. Multiple, Required
4. Multiple, Free tagging
and all got the same results.
I think there is no difference for other cases.
Comment #5
csc4 commentedSame problem.
I have the auto node title set to
TEST [term] [field_reference-formatted] [field_inscription_surnames-formatted]On creation the title is
TEST nnn surnameOn edit the title is
TEST termname nnn surnameI've tried previewing before saving but that makes no difference. Taxonomy in question is a non heirarchical and non-free tagged.
Taxonomy 5.1
Automatic Nodetitles 5.x-1.0
Token 5.x-1.7
Comment #6
gregglesJust changing the title to reflect that this issue affects a subset of the token consumers.
Comment #7
csc4 commentedAre you suggesting this is an autonodetitle issue then? I thought it was pretty clearly a token / taxonomy issue which will affect ALL token users relying on taxonomy support.
Comment #8
eaton commentedThere's an important addition to that: 'all token users relying on taxonomy support during the window of time after a node has been populated but before it's been saved to the database. The majority of token implementations are NOT doing things during that window, and thus won't run into this issue.
I'm not saying it on't be fixed, but I am also trying to figure out the best approach. Token is relatively lightweight, and it depends on modules giving it data that makes sense. In this case, the data isn't yet in a format that makes sense -- it won't be until the node is saved. The question is whether Token.module should special-case for this scenerio, or whether it should be up to modules to hand Token a *node*, not *an object that will soon become a node*.
Comment #9
csc4 commentedI think I understand your drift - but why is
[term]not iopulated at this point when[field_inscription_surnames-formatted]is?!It's not as simple as needing to have a heavier module weight than taxonomy is it?
Comment #10
csc4 commentedWhich module should have the heavier weight?
Has anyone else found out anything about why this happens - and more importantly how it can be fixed?
Comment #11
csc4 commentedStill looking for some help on this - can it be fixed with module weightings and if so which module needs to be first?
If not, is it a bug and if so is there going to be a fixed as currently [term] is unusable - I can't tell my users they have to create a node, save it, edit it, change nothing and save it again!
Comment #12
bomarmonk commentedI'm having similar difficulties. Thanks to anyone who can create a fix for this.
Comment #13
Mac Clemmens commentedYes, I'm having a similar issue -- not only with Autotitle but also with Upload paths. When files are uploaded, they are supposed to go into a directory /[term]/ but they don't because token hasn't gotten the term yet. For my programming experience, I realize this is a probably tricky thing to fix. I do believe that token should take the lead on fixing this issue because many modules depend on token in this way.
Comment #14
bomarmonk commentedIs there a way to do a cron hook for a temporary fix? Let's say after the node has been saved, the term has been set, and then a cron run can come back and properly populate the titles of the nodes, etc? This idea, however, wouldn't seem to work for a directory path, so a different fix would be needed there... so maybe this needs a more robust solution than a cron hook. Just brainstorming possible fixes...
Comment #15
gregglesI think the better solution is to improve the taxonomy parsing code in token to handle a more broad set of cases, but that is quite painful and I haven't had the time/desire to do that.
Comment #16
guardian commentedsubscribing
Comment #17
guardian commentedthe issue was discussed on the auto_nodetitle module issues queue: http://drupal.org/node/147595
i'm not familiar at all with the token module but maybe a new type could be introduced: $type = 'form' ? that would extract the terms from $node->taxonomy ?
Comment #18
guardian commentedfor those wanting a workaround: in fact fago documented README.TXT as an answer to http://drupal.org/node/121216
in my very specific content type example, the workaround consisted in using the php replacement feature of auto_nodetitle:
now, even at preview time, the title is correct. use the devel module to find out which data to retrieve from $form_values.
Comment #19
bomarmonk commentedThank you! I'll have to give this a try!
Comment #20
stormer commentedI've been having the same problem and am massively relieved that there seems to be a work-around. Guardian, are you able to expand on how to implement your solution? Unfortunately I've not been able to figure it out.
many thanks
Ole
Comment #21
summit commentedHi,
Indeed, pPlease explain what to alter.
Thanks in advance,
greetings,
Martijn
Comment #22
ellanylea commentedThanks guardian for the work-around!
Installed the Devel module, which gave 2 more tabs next to the 'View' and 'Edit' tabs. Click on the 'Dev load' tab and see your field.
In admin/settings/devel, checked the box 'Display form element keys and weights'. Then in the node edit page, I saw (key=mon, weight=0) (key=mday, weight=1) (key=year, weight=2) next to my fields.
So in my content type, in the 'Automatic title generation' box, I wrote:
... this gave me 3 29, 2007. But I wanted March 29, 2007. So I changed the code to:
Comment #23
dmitrig01 commentedI've reproduced this. here's how
dog, cat, fishand #2 is freetagging. #2 also has a weight of -9.test [term]Comment #24
dmitrig01 commentedI found the root of this bug.
Auto_nodetitle operates on $op == 'validate'.
Taxonomy operates on $op == 'submit'.
So, there is *no* way we can get preview working, however we can get submit working, and here's how (patch attached).
Comment #25
dmitrig01 commentedComment #26
gregglesReassigning issue to proper queue.
Comment #27
fagoyour patch can't help, as on nodeapi insert or update the node has already been saved. Furthermore as this issue only affects terms, it's not critical.
So apart from improving the token parsing code, I see no clean solution for this. Regenerating the node title on op submit would set another title as has been previewed - not very intuitive. Furthermore it might break existing auto nodetitle configurations.
So if you need this, I suggest you make use of of the php code feature and figure out a working php code.
Comment #28
fagoI'm setting this to postponed to make the issue visible for others. It's still considered to be "by design". :)
Comment #29
gregglesI mostly agree with fago. This patch doesn't fix this problem, though dmitrig01's advice and debugging are enormously valuable.
I'm not sure that we'll ever be able to "solve" this for freetagging. The problem is that freetags can be new tags in which case they don't have a vid/tid until they are saved but we need them before they are saved. Bummer. If you use freetagging please be sure that the term you want to show up for the autonodetitle is of a lower weight than your freetagging vocab.
For regular vocabs and tags, though, the code can be better, and with this patch I think it is.
I'd appreciate any help folks can give in testing this.
Comment #30
samuelet commentedsubscribing
Comment #31
greggles@samuelet - no need to "subscribe" - there is a patch. Test it. Review it. Let us know how it goes.
Comment #32
samuelet commentedsupposing this bug is related to my issue at http://drupal.org/node/186506, then the last patch does not work for me on 5.x.1.9. Should it work only for the dev release?
Comment #33
gregglesIt depends on what you mean by "does not work".
If you mean "hunks of it fail the patch isn't even applied" well then yeah, try the dev.
If you mean "the patch applied fine, but the function still isn't there" then I'd say this is a related but slightly different bug ;)
Comment #34
samuelet commentedI mean it applies but nothing change in pathauto alias building.
It applies with:
Hunk #2 succeeded at 83 (offset -1 lines).
Hunk #3 succeeded at 95 (offset -1 lines).
Comment #35
bomarmonk commentedGreggles, I have tried to patch the token.module with your patch, but Hunk #1, #2, and #3 fail. I have tried this with both the development (5.x-1.x-dev and the official 5). I did notice that CVS shows some last changes for Drupal 6, so maybe this is why this patch no longer applies? Let me know! Thanks.
Comment #36
gregglesI applied this. Thanks dmitrig01 and fago for your investigation and insight.
@bomarmonk - If you wait for the 5.x-1.x-dev tarball to get rerolled tonight then you can just download that tomorrow to test.
Comment #37
gregglesPorted in eaton's work this past weekend.
Comment #38
dmitrig01 commentedI'd recommend we apply my patch. It not only affects terms, it affects anything that gets saved with the node, including the NID!
Comment #39
gregglesdmitrig01, did you test your patch?
In my testing it doesn't seem to actually do or help anything.
ANT works fine for me now that token has been patched.
Comment #40
greggleschanging back to fixed. I don't think there's anything else to do here.
Comment #41
incaic commentedLooking for an answer on this and think this is the right place to ask it.
I've created a file type field so someone can upload a file. I would like
the directory of the uploaded file to be in XXX where XXX is specified
in another form input field.
How can I do this?
I only seem to have access to $user in myModule_token_values ()
How can I get form values?
Seems like something that someone would have done, so as to keep
uploaded files organized.
Comment #42
greggles@incaic - take a look at http://drupal.org/project/uploadpath which deals with (and struggles with) the same problem.
Also, this issue is marked "fixed". There are certainly more scenarios that token needs to handle but I'd like to let this issue die and create new, concise, clear issues for related problems.
Comment #43
incaic commentedThanks greggles!
Just read the description, sounds like a winner.
Sorry about posting my problem here.
Comment #44
(not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #45
dpollen commentedHi... I have been working through a number of related issues related to this.
I have applied both patches...
I have tried the latest DEV versions of the 2 modules as well ( Token & Automatic Nodetitles ).
The node title I am trying to use is:
The [term-raw] token is not evaluated on CREATE... but after EDIT.
Could someone please tell me what I'm doing wrong?
Comment #46
greggles@dpollen - please create a new issue for your problem. Please provide details about the taxonomy configuration (types, weights) and the taxonomy selection when you create the node.
Also, I'm frankly not likely to work on fixing this issue. It's quite difficult to parse tokens properly and accurately before the node is created which is when ANT needs it to be done. So...
Comment #47
seddonym commentedA simple workaround for the [term] tag that I used in Drupal 6. It's more flexible as you can use it for any vocabulary.
Ensure 'Evaluate PHP' is checked and place in the 'Pattern for the title' field:
{Vocabulary id} is where you put the id for the vocabulary you're using, so if I wanted to use the [author-name] token and then the term from Vocabulary 1, I'd use:
Simple!
Comment #48
glennr commentedThis worked perfectly for me too. Thanks for the workaround, seddonym.
Comment #49
jeff124578 commentedMy content type allows multiple taxonomy term selection, so I had to tweak seddonym's code a bit (now that $node->taxonomy[{vocabulary id}] is an array):
Seems to me that we also need to use print instead of return so that subsequent text/tags in the autotitle pattern get included.
Comment #50
laken commentedThanks, this tip solved it for me too - works fine on Drupal 5 as well.
Comment #51
laken commentedOn second glance (again for Drupal 5), I can say the solution in #49 works when the node is saved from the node edit form, bit it doesn't work when using the 'update automatic node titles' action from the admin/content/node page. This seems to be due to a discrepancy in the makeup the $node->taxonomy element. When the node is being saved from the form, $node->taxonomy is a simple array with the first key the vid, and the second key the tid, so the code above works.
Inspecting $node->taxonomy while the form is being submitted yields:
But when then node is already saved, and retrieved via node_load(), $node->taxonomy has a different form:
We need to take this into account when making an auto node title template that will work both when the node form is submitted and for the 'update automatic nodetitle' action from the Content administration page (admin/content/node)
Here's what worked for me:
Comment #52
kompressaur commentedHello i am trying this and the title is being generated as-
//Template - replace {Vocabulary id} with the id for the vocabulary you're using:I am on the latest drupal 6. Am i doing something wrong? thanks
Comment #53
big_smile commentedI am using Drupal 6.
What code do you need to use if you want to reference terms from several different vocabularies?
The code seddonym posted only seems to let you use one vocabulary.
Thanks for any help!
Comment #54
jeffschuler@kompressaur: just leave that line out, entirely. It's a php comment, but it's not inside the
<?php ?>block.Comments in #47 and #49 provided a suitable workaround for me.
Note that #338853: Token malfunction with Auto NodeTitle: [term] replacement fix patch and #476644: Does not see term-raw first time may be duplicates of this issue.
Comment #55
davideads commented#49 worked for me.
printing the string in the PHP snippet is critical if you wish to mix-n-match tokens and PHP code in any order.Comment #56
Rob T commentedA combination of #47 and #49 worked for terms for me.
Comment #57
Stomper commentedI am having similar issues as I have "[nid]" in my autonode title, I too have edit and save to have [nid] show up, oddly enough, I also have a "node field" as part of the title - it is generated on submit.
Can a chron run be set to update them?
Comment #58
wind_kind commentedThe code at #49 works for me but how would I go about selecting the term and its child. My vocabulary looks like this:
Vehicle make
-Alfa
--156
--157
-Aston Martin
--DB5
and I want to get only for example Alfa and 156. With the code from #49 I get only Alfa.
Comment #59
wind_kind commentedI don't know if this is the best way of doing it but I played around with that piece of code until I came up with this and it works, if you can make this any better pleace do, I have no clue about PHP I just got lucky.
Comment #60
aubjr_drupal commentedGo to my summary on available hacks/fixes as of this posting for this problem. I put it together after coming across a lot of posts on this issue and wanted to summarize it for others.