You are here

function commerce_message_message_presave in Commerce Message 7

Implements hook_message_presave().

We cannot use a token to show the order-summary, since both Token and Entity API modules invoke token_generate() which results with an array instead of a string with the replacement text.

Instead, upon saving the message for the first time we inject an argument with a callback, that will return the order summary.

@link http://drupal.org/node/1272560

File

./commerce_message.module, line 60

Code

function commerce_message_message_presave(Message $message) {

  // Only support unsaved messages that re-use our order reference field.
  $wrapper = entity_metadata_wrapper('message', $message);
  if (!empty($message->mid) || !isset($wrapper->message_commerce_order)) {
    return;
  }
  $message->arguments['!order-summary'] = array(
    'callback' => 'commerce_message_order_summary',
    'pass message' => TRUE,
  );
}