Search code examples
drupal-6radio-buttondrupal-theming

Right way to theme radios in Drupal?


I tried theming of radios in Drupal module overriding the following code in my theme function. For experimental I did not change anything in the below function and just migrated into my module with different name that would not conflict with original api function.

function theme_radios($element) {
  $class = 'form-radios';
  if (isset($element['#attributes']['class'])) {
    $class .= ' ' . $element['#attributes']['class'];
  }
  $element['#children'] = '<div class="' . $class . '">' . (!empty($element['#children']) ? $element['#children'] : '') . '</div>';
  if ($element['#title'] || $element['#description']) {
    unset($element['#id']);
    return theme('form_element', $element, $element['#children']);
  }
  else {
    return $element['#children'];
  }
}

Theme registration and all fine. Unfortunately, I am getting nothing as result. Only the form label (Radios's Label) I can see. Any idea please?

EDIT: I managed to solve it. Thanks everyone!


Solution

  • The question is solved. I have posted a blog post on how to do it. Any one need help on similar issue can refer to the link. http://www.encodez.com/blog/how-to-theme-radio-drupal-1.html

    NB: This solution is for Drupal 6.