AutoNodeTitle (ANT) patterns containing [term] do not get evaluated upon node creation. I was able to track down the issue inside node_token_values()@token_node.inc.
I found 2 problems:
* while looping through $node->taxonomy terms, when $vid was not found through db_query, the code issued a "continue" instruction, thus skipping all different approaches to $vid identification.
* the approach for the pre-taxonomy submit case doesn't take in account a case in which $node->taxonomy is an array of numeric values. That makes $term (and $original_term) a simple numeric variable. This scenario happens when ANT calls token_replace().

The attached patch removes the 'continue' instruction and changes the if's for the pre-taxonomy submit case to handle $original_term as an array and as a numeric value.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhedstrom’s picture

FileSize
1.76 KB

This patch works perfectly to resolve #476644: Does not see term-raw first time. I had to reroll it through, since the query that gets moved into the conditional has changed in token since this patch was written ($object->vid instead of $object->nid).

greggles’s picture

Can you provide a simpletest for this?

rus032’s picture

patch don't work. :(
ps latest stable - ANT, Token

Miteto’s picture

Actually it does work, patch applied without a hitch.
Latest stable - Token 6.x-1.12, Automatic Nodetitles 6.x-1.2.

vasike’s picture

subscribe and the solution provided here it seems it works

rc2020’s picture

Was this committed to dev? If not, is it going to be, or do I need to reapply the patch each update?

Thanks...

rc2020’s picture

I get an error when applying the first patch.

Hunk #1 FAILED at 110.

Patch #1 does not work, but patches successfully. The first patch does not apply, generating the error above. Any suggestions?

rc2020’s picture

Also, I don't know what patch to use, the first or second. Currently, I am unable to get ANT working with [term] or [term-raw]. Did anyone successfully get this working? Have these fixes been committed? I can't even keep track of what patches are running and what versions I got. [term] seems to be a pretty widely used token, can I get some update on what is going on with all this?

The second patch (#1) doesen't necessarily succeed, it just doesen't fail. My terminal prompt says 'patching file token_node.inc' but never says hunk succeeded.

I've been going high and low trying to get this fixed, any help would be extremely appreciated

Thanks.

techninja’s picture

What exactly is it going to take to get this rolled into a new release? Is Dev really that far off from the current release? I was able to apply this patch successfully to the current stable release (6.x-1.12) with no warnings, and it even fixes what it says it fixes!

This specific problem has been on the plate for years.. and even this specific issue ticket recently had it's first birthday. Shouldn't we move on and just get it out of the way? I can't mark this as tested by the community because I am not applying the patch to Dev. This is only a small piece of my project and I can't spend too much time working on it especially if I have something that works, but I hate to think this would miss the next official release...

TommyK’s picture

I tried both patches, the one in Comment #1 applies correctly, but seems to have no effect.

I'll create a new term in a node (via tags) and that term is set to show in the title of that node with ANT (along with some other fields). After saving initially, the term does not appear in the title, but does on a subsequent save.

What else could be wrong?

UPDATE: I've flushed caches and ran update.php. I've just found that even when adding an existing term to a new node it doesn't end up in the title on the first save.

TommyK’s picture

I've tried this out again with the most virgin install possible and it still doesn't work.

- patched token-6.x-1.12 with token.338853.patch
- enabled auto_nodetitle-6.x-1.2 and the patched token-6.x-1.12
- setup Automatic Title Generation on Page content type
- set to Automatically generate the title and hide the title field
- pattern for the title: [term] by [author-name]
- setup a Vocabulary as Tags on Page content types

- create a Page
- type a term and a body
- save the node

The result is that the title is initially " by admin" with no term. Upon saving again a term appears in the title.

Should I be doing something differently?

klokie’s picture

Hi, I've gone through the exact same procedure as TommyK, except creating a Story instead of a Page.

I get the same result - the title is " by admin" on first save, and is updated to the correct title beginning with the [term] value upon re-saving the node.

Status: Needs review » Needs work

The last submitted patch, token.338853.patch, failed testing.

DrupalYedi’s picture

same problem

tjb74’s picture

I have tried implementing the patch manually, but still need the node to be save twice for the title to pickup the term name for auto nodetitles.

tjb74’s picture

I ended up sorting my issue by creating a rule: http://drupal.org/node/373978#comment-1654702

flevour’s picture

Assigned: flevour » Unassigned

I am removing my assignment for this issue. I haven't had a single look at this issue in all this time, maybe someone can step up and provide a simpletest as greggles requested at #2.
Sorry if I made this issue lag a "bit".
Francesco

fripplo’s picture

See http://drupal.org/node/476644#comment-3392994 for a workaround without any real coding.

brisath’s picture

Subscribing

aubjr_drupal’s picture

Go 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.

q2_faith’s picture

Status: Needs work » Needs review

#1: token.338853.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, token.338853.patch, failed testing.

q2_faith’s picture

works for me