You are here

function webform_workflow_notify_users in Webform Workflow 7

Notify users of a state transition by e-mail.

Parameters

object $submission: The webform submission entity that has undergone the state transition.

array $transition: Optional: information about the transition, including the keys 'account', 'new_state', 'previous_state', 'timestamp', and 'message'.

Return value

array|FALSE An array of the user accounts who have been notified, or FALSE if no-one has been notified.

1 call to webform_workflow_notify_users()
webform_workflow_transition in ./webform_workflow.module
Change the state of a submission.

File

./webform_workflow.module, line 762
A simple workflow module for webforms.

Code

function webform_workflow_notify_users($submission, array $transition = array()) {
  $notify_users = webform_workflow_get_notify_users($submission);
  if (!$notify_users) {
    return FALSE;
  }
  $notify_emails = array();
  foreach ($notify_users as $account) {
    $notify_emails[] = $account->mail;
  }
  $node = node_load($submission->nid);
  $email_templates = $node->webform_workflow->data['emails'];

  // Note that we need to specify the 'webform-email' data so that Webform's
  // token implementation knows that the tokens are being used in the
  // context of an email.
  $token_data = array(
    'node' => $node,
    'webform-submission' => $submission,
    'webform-email' => array(),
  );
  if ($transition) {
    $token_data += array(
      'webform-workflow-transition' => $transition,
    );
  }
  $token_options = array(
    'clear' => TRUE,
    'sanitize' => FALSE,
  );
  $params = array(
    'subject' => token_replace($email_templates['subject'], $token_data, $token_options),
    'body' => token_replace($email_templates['body'], $token_data, $token_options),
  );
  drupal_mail('webform_workflow', 'state_transition', implode(',', $notify_emails), LANGUAGE_NONE, $params);
  return $notify_users;
}