Hi,

As based on the token description, Body [message:field-node-ref:body:?] The main body text of the node. The following properties may be appended to the token: value (Text), summary (Summary), format (Text format)

However, when I tried [message:field-node-ref:body:value] , [message:field-node-ref:body:summary] , [message:field-node-ref:body:format] , all of them are NOT rendered with value.

Comments

sadashiv’s picture

Status: Active » Needs review

Hi,

I was facing the same issue. One more interesting issue is that if I use [message:field-node-ref:body] then it's not replaced in the email but when I see the message on the site i.e. at /admin/content/message then it shows the message as it should be.

I tried to debug and found that the problem exists in entity_token.tokens.inc

hook_tokens in the file has a code

            $value = ($token_info['type'] == 'struct') ? $wrapper->$property_name : $wrapper->$property_name->value();

The $value returns a complete object when we try to update the node so the token is replaced and we get the complete message and when we create a new node it has all fields empty so the token is not replaced.

I think this may be because the fields are not written to the db or a cached copy of the entity gets served thus it don't have any field data thus failing the token.

I checked node_save and found that it creates the fields and then invokes node_insert so my hook is triggered after the fields are saved so I tried clearing entity_cache before calling message_subscribe_send_message

Use this code before calling the message_subscribe_send_message or message_notify_send_message function

    entity_get_controller('node')->resetCache(array($node->nid));

Here $node is the newly inserted node on which we want to trigger message.

May be this can be included in some documentation so that we reset cache if we want to use the token for new node or can be included in the message_notify

Hth,
Sadashiv.

ndobromirov’s picture

I made it work with just [message:field-node-ref:body] so it might be the description that is broken / incorrect.

bluegeek9’s picture

Status: Needs review » Closed (outdated)