Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
eaton CreditAttribution: eaton commentedFix is checked in and will be added into the next release in a few days. thanks!
Comment #2
(not verified) CreditAttribution: commentedComment #3
dodorama CreditAttribution: dodorama commentedMy 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.
Comment #4
ray007 CreditAttribution: ray007 commentedMaybe we could use a call to
theme(...)
or one of its variants instead of content_format()?I'm looking a bit into this too ...
Comment #5
dodorama CreditAttribution: dodorama commentedpassing content_format to the strip_tags function like this:
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.
Comment #6
ray007 CreditAttribution: ray007 commentedI 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 ...
Comment #7
KarenS CreditAttribution: KarenS commentedThere 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.
Comment #8
KarenS CreditAttribution: KarenS commentedNote 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.
Comment #9
eaton CreditAttribution: eaton commentedThat'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...
Comment #10
eaton CreditAttribution: eaton commentedA 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.
Comment #11
eaton CreditAttribution: eaton commentedFor now, I'm going to set this to fixed. Version 1.5 appears to solve the problem in a very robust fashion.
Comment #12
(not verified) CreditAttribution: commented