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.
I am using the example code given on https://www.drupal.org/node/2180227:
/*
* Implements hook_node_insert().
*/
function foo_node_insert($node) {
$message = message_create('foo_message_type', array('uid' => $node->uid));
$wrapper = entity_metadata_wrapper('message', $message);
$wrapper->field_node_ref->set($node);
$options = array(
'rendered fields' => array(
'message_notify_email_subject' => 'field_rendered_subject',
'message_notify_email_body' => 'field_rendered_body',
),
);
message_notify_send_message($message, $options);
}
and it works fine for the message subject, but for some reason I can't get node body to be mailed properly. Tokens for for subject filed, but again body tokens always return empty.
I tried to see the content of the $node variable in the following code from example module:
elseif (isset($message['params']['message_entity']->field_node_ref)) {
// This is a node.
$nid = $message['params']['message_entity']->field_node_ref[LANGUAGE_NONE][0]['target_id'];
$node = node_load($nid);
$messageid_params['uid'] = $node->uid;
$messageid_params['nid'] = $node->nid;
$messageid_params['cid'] = 0;
$messageid_params['time'] = $node->created;
if (variable_get('mailcomment_alter_subjects', 1)) {
$subject = $message['subject'];
$subject = variable_get('site_name', '') ? '[' . variable_get('site_name', '') . '] ' . $node->title : $subject;
$message['subject'] = $subject;
}
dpm($node);
}
and unfortunately my custom node body field returns empty:
field_description (Array, 0 elements)
$...->field_description
I wonder is this because the above code is trigerred while the node has not been saved yet? But then how can I make Message module to send node body?
Comments
Comment #2
bluegeek9 CreditAttribution: bluegeek9 as a volunteer commented