The function to generate tokens for CCK fields doesn't use formatters causing most fields (e.g. date_field) to not work.
Here's how the function should be changed:

function content_token_values($type, $object = NULL) {
  $tokens = array();
  if ($type == 'node') {
    $node = $object;

    foreach (content_fields() as $field) {
      $items = $node->$field['field_name'];
      $tokens[''. $field['field_name'] .''] = content_format($field['field_name'], $items[0]);
    }
  }
  return $tokens;
}

Comments

eaton’s picture

Status: Needs review » Fixed

Fix is checked in and will be added into the next release in a few days. thanks!

Anonymous’s picture

Status: Fixed » Closed (fixed)
dodorama’s picture

Status: Closed (fixed) » Active

My solution above isn't enough. There are still problems with CCK tokens.
Adding content_format isn't enough. Tags aren't stripped (see http://drupal.org/node/114256) and the date field needs a special treatment (see http://drupal.org/node/108803#comment-184293, http://drupal.org/node/114610 and http://drupal.org/node/114579) .
I'm afraid but I'm not able to provide a proper patch (I spent the whole day trying to with no luck).
If there's anyone with more php coding skills than me it could be useful to see this patch to the date field module that integrates it with pathauto and take a look to content_pathauto.inc inside the CCK package that can be taken as an example on how to serve standard cck fields.

ray007’s picture

Maybe we could use a call to theme(...) or one of its variants instead of content_format()?
I'm looking a bit into this too ...

dodorama’s picture

passing content_format to the strip_tags function like this:

strip_tags(content_format($field['field_name'], $items[0]))

seems to work. I'm testing it right now and I don't have any tags for text and link fields.
There are still issues with the date field that always print 1 Jan 2007.

ray007’s picture

I have been experimenting a bit:
first replace the line
$node = $object;
with
$node = node_build_content($object, false, false);
You now have some view-properties set on the fields.
In my testing with date-fields, I now sometimes seem to get the right result in debugging:
if you check $items[0]['value'] and $items[0]['view'], one of those will be correct, but I haven't yet found a way to say which one ...

KarenS’s picture

There were some bugs in the new from/to date handling in the date module that is now fixed that might have been part of the problem here, so be sure you are using the latest version of that code.

You should always use either the 'view' property or content_format(). They should produce the same results.

KarenS’s picture

Note my response to http://drupal.org/node/114579. Widget_invoke 'process form values' needs to get run on the node before doing replacements. I'm not sure whether this is something that needs to be fixed in the token module or in auto_nodetitles.

eaton’s picture

That's a tricky question, Karen. The Token module assumes that the object given to it in the 'node' context is a normal node -- not a semi-initialized node that we have during form processing. Perhaps it might be better to have a 'form' token context that can grab explicit form values? Or, alternately, have auto_nodetitles to the widget processing before handing the node to Token module for replacement...

eaton’s picture

Status: Active » Needs review

A new approach to this problem has been checked in as part of the new dev snapshot of token.module. *each field type* gets an opportunity to provide its own tokens, and the handling can be a bit more intelligent. Token replacement code is now included for all the core CCK types, and I've also added an appropriate hook to asin.module.

date.module, link.module, and image.module are notably absent right now. I'd like to see if I can get feedback from folks on the current dev snapshot and see what they think. Thanks.

eaton’s picture

Status: Needs review » Fixed

For now, I'm going to set this to fixed. Version 1.5 appears to solve the problem in a very robust fashion.

Anonymous’s picture

Status: Fixed » Closed (fixed)