Contributions API

theme_webform_mail_fields

Definition

theme_webform_mail_fields($cid, $value, $node, $indent = "")
contributions/webform/webform.module, line 1762

Description

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 intialy 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.

Code

<?php
function theme_webform_mail_fields($cid, $value, $node, $indent = "") {
  // First check for component-level themes.
  $themed_output = theme("webform_mail_". $node->webform['components'][$cid]['type'], $value, $node->webform['components'][$cid]);
  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";
  }
  // Generic output for single values.
  elseif (!is_array($value)) {
    // Note that newlines cannot be preceeded by spaces to display properly in some clients.
    if ($node->webform['components'][$cid]['name']) {
      // If text is more than 60 characters, put it on a new line with space after.
      $long = (strlen($indent . $node->webform['components'][$cid]['name'] . $value)) > 60;
      $message .= $indent . $node->webform['components'][$cid]['name'] .":". (empty($value) ? "\n" : ($long ? "\n$value\n\n" : " $value\n"));
    }
  }
  // Else use a generic output for arrays.
  else {
    $message .= $indent . $node->webform['components'][$cid]['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);
}
?>