You are here

function theme_webform_element_text in Webform 7.4

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

Output a form element in plain text format.

File

./webform.module, line 3838
This module provides a simple way to create forms and questionnaires.

Code

function theme_webform_element_text($variables) {
  $element = $variables['element'];
  $value = $variables['element']['#children'];
  $output = '';
  $is_group = webform_component_feature($element['#webform_component']['type'], 'group');

  // Output the element title.
  if (isset($element['#title'])) {
    if ($is_group) {
      $output .= '==' . $element['#title'] . '==';
    }
    elseif (!in_array(drupal_substr($element['#title'], -1), array(
      '?',
      ':',
      '!',
      '%',
      ';',
      '@',
    ))) {
      $output .= $element['#title'] . ':';
    }
    else {
      $output .= $element['#title'];
    }
  }

  // Wrap long values at 65 characters, allowing for a few fieldset indents.
  // It's common courtesy to wrap at 75 characters in e-mails.
  if ($is_group && drupal_strlen($value) > 65) {
    $value = wordwrap($value, 65, "\n");
    $lines = explode("\n", $value);
    foreach ($lines as $key => $line) {
      $lines[$key] = '  ' . $line;
    }
    $value = implode("\n", $lines);
  }

  // Add the value to the output. Add a newline before the response if needed.
  $output .= (strpos($value, "\n") === FALSE ? ' ' : "\n") . $value;

  // Indent fieldsets.
  if ($is_group) {
    $lines = explode("\n", $output);
    foreach ($lines as $number => $line) {
      if (strlen($line)) {
        $lines[$number] = '  ' . $line;
      }
    }
    $output = implode("\n", $lines);
    $output .= "\n";
  }
  if ($output) {
    $output .= "\n";
  }
  return $output;
}