Set message data in code

Created on 28 May 2013, about 11 years ago
Updated 15 January 2024, 5 months ago

I'm trying to figure out how to set a message using code?

The content of my mails are generated by another module but I want to use the Message and Message Notify to store the mails and send the mails, since it all fits in with the existing views/logs/history functionality.

But how can I set the message data properly in code?

I had a good look at the Examples in Message but I still miss some parts.

Case: I want to extend the "commerce_order_created" message type, so I added extra fields.

/**
 * Implements custom function().
 */
function MYMODULE_message_insert_status($order, $communication) {
  // Load data
  $account = user_load($order->uid);

  $message = message_create('commerce_order_created', array(), $account);
  $message->message_commerce_order[LANGUAGE_NONE][0]['target_id'] = $order->order_id;

  // Save reference to the order in the order reference field, and the
  $wrapper = entity_metadata_wrapper('message', $message);

  $now = time();
  $wrapper->field_confirmation_date_created->set($now); // Custom fields to extend the commerce_order_created message type
  $wrapper->field_confirmation_date_send->set($now); // Custom fields to extend the commerce_order_created message type

  // Save message
  $wrapper->save();
}

How can I set the data for?
Notify - Email subject
Notify - Email body

I loaded the message object and there these fields are not present?

πŸ’¬ Support request
Status

Closed: outdated

Version

2.5

Component

Documentation

Created by

πŸ‡§πŸ‡ͺBelgium thim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024