You are here

function theme_webform_number in Webform 6.3

Same name and namespace in other branches
  1. 7.4 components/number.inc \theme_webform_number()
  2. 7.3 components/number.inc \theme_webform_number()

Theme function to render a number component.

1 theme call to theme_webform_number()
webform_elements in ./webform.module
Implements hook_elements().

File

components/number.inc, line 222
Webform module number component.

Code

function theme_webform_number($element) {

  // This IF statement is mostly in place to allow our tests to set type="text"
  // because SimpleTest does not support type="number".
  if (!isset($element['#attributes']['type'])) {
    $element['#attributes']['type'] = 'number';
  }

  // Step property *must* be a full number with 0 prefix if a decimal.
  if (!empty($element['#step']) && !is_int($element['#step'] * 1)) {
    $decimals = strlen($element['#step']) - strrpos($element['#step'], '.') - 1;
    $element['#step'] = sprintf('%1.' . $decimals . 'F', $element['#step']);
  }

  // If the number is not an integer and step is undefined/empty, set the "any"
  // value to allow any decimal.
  if (empty($element['#integer']) && empty($element['#step'])) {
    $element['#step'] = 'any';
  }
  elseif ($element['#integer'] && empty($element['#step'])) {
    $element['#step'] = 1;
  }

  // Convert properties to attributes on the element if set.
  foreach (array(
    'id',
    'name',
    'value',
    'size',
    'min',
    'max',
    'step',
  ) as $property) {
    if (isset($element['#' . $property]) && $element['#' . $property] !== '') {
      $element['#attributes'][$property] = $element['#' . $property];
    }
  }
  _form_set_class($element, array(
    'form-text',
    'form-number',
  ));
  $output = '';
  if (isset($element['#field_prefix'])) {
    $output .= '<span class="field-prefix">' . $element['#field_prefix'] . '</span> ';
  }
  $output .= '<input' . drupal_attributes($element['#attributes']) . ' />';
  if (isset($element['#field_suffix'])) {
    $output .= ' <span class="field-suffix">' . $element['#field_suffix'] . '</span>';
  }
  return theme('form_element', $element, $output);
}