You are here

function _webform_render_textfield in Webform 7.4

Same name and namespace in other branches
  1. 5.2 components/textfield.inc \_webform_render_textfield()
  2. 5 components/textfield.inc \_webform_render_textfield()
  3. 6.3 components/textfield.inc \_webform_render_textfield()
  4. 6.2 components/textfield.inc \_webform_render_textfield()
  5. 7.3 components/textfield.inc \_webform_render_textfield()

Implements _webform_render_component().

File

components/textfield.inc, line 146
Webform module textfield component.

Code

function _webform_render_textfield($component, $value = NULL, $filter = TRUE, $submission = NULL) {
  $node = isset($component['nid']) ? node_load($component['nid']) : NULL;
  $element = array(
    '#type' => 'textfield',
    '#title' => $filter ? webform_filter_xss($component['name']) : $component['name'],
    '#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before',
    '#default_value' => $filter ? webform_replace_tokens($component['value'], $node) : $component['value'],
    '#required' => $component['required'],
    '#weight' => $component['weight'],
    '#field_prefix' => empty($component['extra']['field_prefix']) ? NULL : ($filter ? webform_filter_xss($component['extra']['field_prefix']) : $component['extra']['field_prefix']),
    '#field_suffix' => empty($component['extra']['field_suffix']) ? NULL : ($filter ? webform_filter_xss($component['extra']['field_suffix']) : $component['extra']['field_suffix']),
    '#description' => $filter ? webform_filter_descriptions($component['extra']['description'], $node) : $component['extra']['description'],
    '#attributes' => $component['extra']['attributes'],
    '#theme_wrappers' => array(
      'webform_element',
    ),
    '#translatable' => array(
      'title',
      'description',
      'field_prefix',
      'field_suffix',
      'placeholder',
    ),
  );
  if ($component['required']) {
    $element['#attributes']['required'] = 'required';
  }
  if ($component['extra']['placeholder']) {
    $element['#attributes']['placeholder'] = $component['extra']['placeholder'];
  }
  if ($component['extra']['disabled']) {
    if ($filter) {
      $element['#attributes']['readonly'] = 'readonly';
    }
    else {
      $element['#disabled'] = TRUE;
    }
  }

  // Enforce uniqueness.
  if ($component['extra']['unique']) {
    $element['#element_validate'][] = 'webform_validate_unique';
  }

  // Change the 'width' option to the correct 'size' option.
  if ($component['extra']['width'] > 0) {
    $element['#size'] = $component['extra']['width'];
  }
  if ($component['extra']['maxlength'] > 0) {
    $element['#maxlength'] = $component['extra']['maxlength'];
  }
  if ($component['extra']['minlength'] > 0) {
    $element['#minlength'] = $component['extra']['minlength'];
  }
  if (isset($value[0])) {
    $element['#default_value'] = $value[0];
  }
  return $element;
}