I have added following lines to token_cck.inc to support cck_computed fields.

I have only tested it using number and string values (cause that's what I'm using it for now).
I have no knowledge of supplying patches etc, but here is the code I used:
(maybe somebody could pick-it up and review it?)

if (module_exists('computed_field')) {
  function computed_field_token_list($type = 'all') {
    if ($type == 'field' || $type == 'all') {
      $tokens = array();

      $tokens['computed_field']['raw']       = t("Raw, unfiltered text.");
      $tokens['computed_field']['formatted'] = t("Formatted and filtered text.");

      return $tokens;
    }
  }

  function computed_field_token_values($type, $object = NULL, $options = array()) {
    if ($type == 'field') {
      $item = $object[0];
      $tokens['raw']  = $item['value'];
      $tokens['formatted'] = $item['view'];
      return $tokens;
    }
  }
}
CommentFileSizeAuthor
#1 token_computed_field.patch862 bytesGidgidonihah

Comments

Gidgidonihah’s picture

Status: Active » Needs review
StatusFileSize
new862 bytes

I came here looking for precisely this. Added it to my code and it works beautifully.

The only suggestion I might have is the having it display like you set the computed field to display.
Though this isn't really an issue, as you can do that easily in the auto_nodetitle as well. It just makes you do it twice.

Also, rolled a patch for the change. My first patch. Let me know if it works.

ardas’s picture

+1

I have applied this fix. It is very useful.

greggles’s picture

Project: Token » Computed Field
Version: 5.x-1.9 » 5.x-1.2
Status: Needs review » Needs work

Thanks for the idea and contributing the code.

This should be implemented in computed field, not in the token module itself. It's basically the exact same code, but without the module_exists.

Also, I'm dubious about using "raw" as the field name instead of, perhaps "computed_field-raw" for example, but I leave that up to you as the implementers and users of the code.

clivesj’s picture

@greggles:
I followed the examples of date, noderefference etc. Al those token are included in token_cck.inc.
Do I understand it well that I should put the code into a seperate cck_computed_field.inc file?
You are right about "raw".
I will try to supply a patch somewhere next week

greggles’s picture

@clivesj - all of those tokens _were_ included in token_cck. They are increasingly not included there because including tokens from other modules into token core can cause problems when those modules create a new branch (see event 5.x-1.x vs. 5.x-2.x token problems, Date module 5.x-1.x vs. 5.x-2.x problems, etc.)

Initially token module provided support for those while token module was "young". I think now people see the value of the module and since it makes more sense to put it elsewhere we are promoting that idea.

As to where it should be included into the cck_computed_field module - that depends to the module maintainer for that module. In my opinion, they should simply go into the computed_field.module file itself.

clivesj’s picture

Thanks, that clarifies things.

clivesj’s picture

Status: Needs work » Closed (fixed)

I have filed a new issue proposing a patch for the computed_field.module.
So i'll close this one

Gidgidonihah’s picture

New thread located at http://drupal.org/node/243775