You are here

function theme_webform_mail_fields in Webform 6.2

Same name and namespace in other branches
  1. 5.2 webform.module \theme_webform_mail_fields()
  2. 5 webform.inc \theme_webform_mail_fields()

Prepare to theme the fields portion of the e-mails sent by webform.

This function calls itself recursively to maintain the tree structure of components in the webform. It is called intially by theme_webform_create_mailmessage().

Parameters

$cid: The parent component ID we're currently printing.

$value: The value of the component to be printed. May be an array of other components.

$node: The full node object.

$indent: The current amount of indentation being applied to printed components.

1 theme call to theme_webform_mail_fields()
webform-mail.tpl.php in ./webform-mail.tpl.php
Customize the e-mails sent by Webform after successful submission.

File

./webform.module, line 2057

Code

function theme_webform_mail_fields($cid, $value, $node, $indent = "") {
  $component = $cid ? $node->webform['components'][$cid] : null;

  // Check if this component needs to be included in the email at all.
  if ($cid && !$component['email'] && !in_array($component['type'], array(
    'markup',
    'fieldset',
    'pagebreak',
  ))) {
    return '';
  }

  // First check for component-level themes.
  $themed_output = theme('webform_mail_' . $component['type'], $value, $component);
  $message = '';
  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 ($component['name']) {

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