You are here

function theme_webform_mail_fields in Webform 5

Same name and namespace in other branches
  1. 5.2 webform.module \theme_webform_mail_fields()
  2. 6.2 webform.module \theme_webform_mail_fields()
1 theme call to theme_webform_mail_fields()
theme_webform_create_mailmessage in ./webform.inc
Theme the contents of emails sent by webform.

File

./webform.inc, line 216

Code

function theme_webform_mail_fields($key, $value, $node, $indent = "") {

  // First check for component-level themes.
  $themed_output = theme("webform_mail_" . $node->webformcomponents[$key]['type'], $value, $node->webformcomponents[$key]);
  if ($themed_output) {

    // Indent the output and add to message.
    $message .= $indent;
    $themed_output = rtrim($themed_output, "\n");
    $message .= str_replace("\n", "\n" . $indent, $themed_output);
    $message .= "\n";
  }
  elseif (!is_array($value)) {

    // Note that newlines cannot be preceeded by spaces to display properly in some clients.
    if ($node->webformcomponents[$key]['name']) {

      // If text is more than 60 characters, put it on a new line with space after.
      $long = strlen($indent . $node->webformcomponents[$key]['name'] . $value) > 60;
      $message .= $indent . $node->webformcomponents[$key]['name'] . ":" . (empty($value) ? "\n" : ($long ? "\n{$value}\n\n" : " {$value}\n"));
    }
  }
  else {
    $message .= $indent . $node->webformcomponents[$key]['name'] . ":\n";
    foreach ($value as $k => $v) {
      foreach ($node->webformcomponents as $local_key => $local_value) {
        if ($local_value['form_key'] == $k && $local_value['parent'] == $key) {
          $form_key = $local_key;
          break;
        }
      }
      $message .= theme('webform_mail_fields', $form_key, $v, $node, $indent . "  ");
    }
  }
  return $message;
}