I'm not it's probably not a good idea to do this for performance reasons, but for the sake of understanding what's going on in token, I'd like to know why the following does not include the CCK fields in mytoken:

function mymodule_token_values($type, $object = NULL, $options = array()) {
  $values = array();
  switch ($type) {
    case 'node':
      $node = $object;
      $values['mytoken'] = node_view($node);
    break;
  }

  return $values;
}

When I use this token in an email with rules, it does not contain the CCK fields value but only the title of the node. Note this is on new node submission. Inspecting $object, it seems token already partially renders it, which might explain why it cannot be used in node_view?

Comments

Dave Reid’s picture

Status: Active » Fixed

You'd want to look at cck's content.token.inc file to see how they do it:

      $type = content_types($node->type);
      $node->build_mode = 'token';
      $node->content = array();
      content_view($node);
      // The formatted values will only be known after the content has been rendered.
      drupal_render($node->content);
      content_alter($node);

Keep in mode the $node object is passed by reference, so you should use drupal_clone() before calling it through any view/build type functions.

Status: Fixed » Closed (fixed)

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

kenorb’s picture

Any contributed module which provides this token?
Something similar to node_embed, but which support token?

kenorb’s picture

kenorb’s picture

Status: Closed (fixed) » Active

Any working examples or other solutions?

Dave Reid’s picture

Status: Active » Fixed

Not that we know of.

Status: Fixed » Closed (fixed)

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