Text Size
Sunday, May 20, 2012
Get a look down
Drupal >> Code snippets >> How to override radios theme in Drupal
Tuesday, 19 July 2011 13:48

How to override radios theme in Drupal

Written by Nabil Sadki
Rate this item
(1 vote)

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'];
  }
}
Last modified on Tuesday, 19 July 2011 14:10
Nabil Sadki

Nabil Sadki

Hello, I am Nabyl, a Freelance web developer and a joomla addict. I have made many sites using the latter, but also patches for the core of this CMS. I like HipHop culture and world of warcraft. You can find find me on Twitter when i'm free...

Website: www.coins.ma E-mail: This e-mail address is being protected from spambots. You need JavaScript enabled to view it

Add comment



Usefull tricks