Text Size
Sunday, May 20, 2012
Get a look down
General >> Displaying items by tag: radios
Displaying items by tag: radios
Tuesday, 19 July 2011 13:48

How to override radios theme in Drupal

You can override the default radios theme by inserting this little code in your template.php file. You can find the default theme function in form.inc in the core folder : includes.

PS: this code is applicable on all form elements, just copy/paste the initial theme function from form.inc (the initial theme function name for our example is theme_radios() ) into your template.php, and rename the function E.g : theme_radios() => your_theme_name_radios()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
function etinker_radios($element) {
  $class = 'form-radios';
  if (isset($element['#attributes']['class'])) {
    $class .= ' ' . $element['#attributes']['class'];
  }
  $element['#children'] = (!empty($element['#children']) ? $element['#children'] : '');
  if ($element['#title'] || $element['#description']) {
    unset($element['#id']);
    return theme('form_element', $element, $element['#children']);
  }
  else {
    return $element['#children'];
  }
}
Published in Code snippets
Usefull tricks