You are here

function theme_webform_element_wrapper in Webform 6.3

Wrap form elements in a DIV with appropriate classes and an ID.

This is a temporary work-around until we can use theme_webform_element() for all webform form elements in Drupal 7.

File

./webform.module, line 2615

Code

function theme_webform_element_wrapper($element, $content) {

  // All elements using this for display only are given the "display" type.
  if (isset($element['#format']) && $element['#format'] == 'html') {
    $type = 'display';
  }
  else {
    $type = isset($element['#type']) && !in_array($element['#type'], array(
      'markup',
      'textfield',
      'webform_email',
      'webform_number',
    )) ? $element['#type'] : $element['#webform_component']['type'];
  }

  // Convert the parents array into a string, excluding the "submitted" wrapper.
  $nested_level = $element['#parents'][0] == 'submitted' ? 1 : 0;
  $parents = str_replace('_', '-', implode('--', array_slice($element['#parents'], $nested_level)));
  $wrapper_classes = array(
    'webform-component',
    'webform-component-' . $type,
  );
  if (isset($element['#title_display']) && strcmp($element['#title_display'], 'inline') === 0) {
    $wrapper_classes[] = 'webform-container-inline';
  }
  $output = '';
  $output .= '<div class="' . implode(' ', $wrapper_classes) . '" id="webform-component-' . $parents . '">';
  $output .= $content;
  $output .= '</div>';
  return $output;
}