You are here

function webform_format_email_subject in Webform 6.3

Same name and namespace in other branches
  1. 7.4 webform.module \webform_format_email_subject()
  2. 7.3 webform.module \webform_format_email_subject()

Given an email subject, format it with any needed replacements.

3 calls to webform_format_email_subject()
webform_emails_form in includes/webform.emails.inc
Overview form of all components for this webform.
webform_submission_resend in includes/webform.submissions.inc
Form to resend specific e-mails associated with a submission.
webform_submission_send_mail in includes/webform.submissions.inc
Send related e-mails related to a submission.

File

./webform.module, line 3219

Code

function webform_format_email_subject($subject, $node = NULL, $submission = NULL) {
  if ($subject == 'default') {
    $subject = webform_variable_get('webform_default_subject');
  }
  elseif (is_numeric($subject) && isset($node->webform['components'][$subject])) {
    $component = $node->webform['components'][$subject];
    if (isset($submission->data[$subject]['value'])) {
      $display_function = '_webform_display_' . $component['type'];
      $value = $submission->data[$subject]['value'];

      // Convert the value to a clean text representation if possible.
      if (function_exists($display_function)) {
        $display = $display_function($component, $value, 'text');
        $display['#theme_wrappers'] = array();
        $display['#webform_component'] = $component;
        $subject = str_replace("\n", ' ', drupal_render($display));
      }
      else {
        $subject = $value;
      }
    }
    else {
      $subject = t('Value of "!component"', array(
        '!component' => $component['name'],
      ));
    }
  }

  // Convert arrays to strings (may happen if checkboxes are used as the value).
  if (is_array($subject)) {
    $subject = reset($subject);
  }
  return _webform_filter_values($subject, $node, $submission, NULL, FALSE, TRUE);
}