I've been banging my head on my keyboard for weeks trying to figure this out. The solution's probably right in front of my face, but I can't find it.

I'm trying to use [field_type-formatted] tokens in my autonodetitles, but it hasn't worked since I upgraded by D5.7 to D6. The token is empty (i.e., returns nothing). [field_type-raw] works just fine.

As far as I can tell, the problem is that $item['view'] is empty, but I can't figure out why. So the issue is somewhere in the CCK module, not the Token module.

When I examine a node using the devel module (in Dev load or Dev render), I see things like this in Dev load:

$node->field_type(array, 1 element)
Array ( [0] => Array ( [value] => foo ) )

and this in Dev render:

$node->field_type(array, 1 element)
Array ( [0] => Array ( [value] => foo [safe] => foo ) )

but no [view] => foo.

Is there something that I'm doing wrong? How can I restore get my [field_type-formatted] tokens to work?

Comments

yched’s picture

Category: support » bug

Hm. Field rendering has changed in D6, and the 'view' element is populated later on. Turning this into a bug report if this breaks tokens - needs investigation.

grobemo’s picture

Thanks, yched.

Has anyone else had this problem? Or has anyone been successful using [field_type-formatted] tokens in D6?

Yoda99’s picture

I think i have the same problem, posted it a while ago to no avail. Tried the forums too since i thought it might not be cck/drupal but my very limited php-knowledge.

http://drupal.org/node/236944

In short i cant get to theme a cck output with ['view'] but if I drop it (raw as you describe it) it works.

grobemo’s picture

I've spent several hours on this problem today, with only limited progress. $field_type[delta]['view'] gets set by template_preprocess_content_field_view content.module. If I print $variables at the end of that function, everything seems to be fine.

However, $field_type[delta]['view'] (and $field_type[delta]['empty']) are both missing by the time node-field_type.tpl.php is called. I think this is why you're having the problem you are, Yoda.

So perhaps what we need to figure out is why $field_type[delta]['empty'] doesn't exist when node-field_type.tpl.php is being called. This is bigger than just a Tokens-related issue, I think. But I still can't help but wonder why there aren't more people asking about $field_type[delta]['view']. Maybe there's something obvious that I'm missing.

yched’s picture

Title: Problems with $item['view'], content.token.inc, and autonodetitle » Problems with $item['view'], tokens and node.tpl.php

Both problems are a side effect of the 'formatters as theme functions' refactoring in D6. The formatted value is not known until the $node->content gets run in drupal_render.

I fixed this by adding an implementation of hook_nodeapi('alter'), that runs after $node->content is rendered and adds back the formatted 'view' value in $node->field_*[n].
fieldgroup.module need to do the same for fields it 'moves' in groups, but I'll add that is a separate patch (too late tonight :-/). Leaving the bug open for this.

@davidmorrow : I assume it hasn't been reported earlier because not that many people already started to customise their node templates in D6...

yched’s picture

Status: Active » Fixed

Committed the followup fix for fields in fieldgroups.

grobemo’s picture

Fantastic. Thanks so much, yched. I can now use $field_type['view'] in node.tpl.php and my [field_type-formatted] tokens are working just fine.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

onepartscissors’s picture

Hi yched

i'm having a similar problem as is described here, and i've been battling it for weeks now... can you give me more info on the hook_nodeapi('alter') that your mentioned in your post #5...

I fixed this by adding an implementation of hook_nodeapi('alter'), that runs after $node->content is rendered and adds back the formatted 'view' value in $node->field_*[n].

can you post the code for this, or an explanation of how to do this, please?

Thank you!

yched’s picture

@onepartscissors : the fix went in the CCK code, there's nothing for you to add.
If you're still having problem with tokens, maybe it because of #299558: Field data not obtainable when visibility set to hidden. ?

yched’s picture

"there's nothing for you to add"
just make sure you get latest CCK 6.x-2.x code