You are here

function eldir_form_element in Hostmaster (Aegir) 6

Override of theme_form_element(). Take a more sensitive/delineative approach toward theming form elements.

File

themes/eldir/template.php, line 78

Code

function eldir_form_element($element, $value) {
  $output = '';

  // Add a wrapper id
  $attr = array(
    'class' => '',
  );
  $attr['id'] = !empty($element['#id']) ? "{$element['#id']}-wrapper" : NULL;

  // Type logic
  $label_attr = array();
  $label_attr['for'] = !empty($element['#id']) ? $element['#id'] : '';
  if (!empty($element['#type']) && in_array($element['#type'], array(
    'checkbox',
    'radio',
  ))) {
    $label_type = 'label';
    $attr['class'] .= ' form-item form-option';
  }
  else {
    $label_type = 'label';
    $attr['class'] .= ' form-item';
  }

  // Generate required markup
  $required_title = t('This field is required.');
  $required = !empty($element['#required']) ? "<span class='form-required' title='{$required_title}'>*</span>" : '';

  // Generate label markup
  if (!empty($element['#title'])) {
    $title = t('!title: !required', array(
      '!title' => filter_xss_admin($element['#title']),
      '!required' => $required,
    ));
    $label_attr = drupal_attributes($label_attr);
    $output .= "<{$label_type} {$label_attr}>{$title}</{$label_type}>";
    $attr['class'] .= ' form-item-labeled';
  }

  // Add child values
  $output .= "{$value}";

  // Description markup
  $output .= !empty($element['#description']) ? "<div class='description'>{$element['#description']}</div>" : '';

  // Render the whole thing
  $attr = drupal_attributes($attr);
  $output = "<div {$attr}>{$output}</div>";
  return $output;
}