I'd like to have my own custom module alter the message composition in _messaging_sendto_compose(). I don't think this is doable right now but let me know if it is. messaging_sendto should make a hook available that my module could implement. It should make available all the parameters ($method, $destination, $values, $preview) and allow me to alter the $message array.

To give you an idea of what I was doing, I wanted to alter some message params depending on data in an extra field that I added to the form, and also add some attachments:

 if (isset($values['gateway'])) {
  $message['params']['sms'] = $values['gateway'];
}
if (!empty($values['node']->files)) {
  $message['attachments'] = $values['node']->files;
}
if (!empty($values['node']->field_image)) {
  foreach ($values['node']->field_image as $file) {
    $message['attachments'][] = (object) $file;
  }
} 

Comments

mfb’s picture

Question about how to implement this: Should we store the $values (which includes $values['node']) in the $message object, so contrib modules have access to the sendto "context" and can use message_alter() to alter the message? This might be preferable to adding a new hook as I suggested above.

David Goode’s picture

Hey, attachments are in the works in messaging in general, I'll try to look into utilizing that functionality for this module. You could also try hook_message_alter() or similar on the messaging side of things.

David

mfb’s picture

When altering the message, I need access to the form values (including the node object, and also any custom form fields I am adding via form_alter). Seems like I need either a new hook, or for messaging_sendto to make the form values available somewhere in the message object.