1 form.inc form_pre_render_conditional_form_element($element)

Adds form element theming to an element if its title or description is set.

This is used as a pre render function for checkboxes and radios.

Related topics

File

core/includes/form.inc, line 3248
Functions for form and batch generation and processing.

Code

function form_pre_render_conditional_form_element($element) {
  $t = get_t();
  // Set the element's title attribute to show #title as a tooltip, if needed.
  if (isset($element['#title']) && $element['#title_display'] == 'attribute') {
    $element['#attributes']['title'] = $element['#title'];
    if (!empty($element['#required'])) {
      // Append an indication that this field is required.
      $element['#attributes']['title'] .= ' (' . $t('Required') . ')';
    }
  }

  // Merge in any wrapper attributes.
  if (isset($element['#wrapper_attributes'])) {
    $element['#attributes'] = array_merge($element['#attributes'], $element['#wrapper_attributes']);
  }

  // Add the element type to the wrapping container.
  if (isset($element['#type'])) {
    $element['#attributes']['class'][] = 'form-' . $element['#type'];
    if (isset($element['#parents']) && form_get_error($element) !== NULL && !empty($element['#validated'])) {
      $element['#attributes']['class'][] = 'form-error';
    }
  }

  // The disabled attribute is only shown on the children, not on the wrapper.
  if (isset($element['#attributes']['disabled'])) {
    unset($element['#attributes']['disabled']);
  }

  if (isset($element['#title']) || isset($element['#description'])) {
    $element['#theme_wrappers'][] = 'form_element';
  }

  return $element;
}