Skip to main content
edited body
Source Link
Clive
  • 168.5k
  • 19
  • 305
  • 338

If you're just adding a class to the attributes array a template_preprocess hook would be sufficient, and stop you having to copy the entire thing, e.g.

function MYTHEME_preprocess_form_element(&$vars) { $vars['attrbiutes']['class'][]$vars['attributes']['class'][] = 'another-class'; } 

If you need to add a wrapper around the outer element you can do something like this

function MYTHEME_form_element($vars) { $original = theme_form_element($vars); return '<div class="something">' . $original . '</div>'; } 

But if you need to add an extra attribute to an internal element of that theme function, you'll need to copy the whole thing over. PHP offers no way to pick a section of a function to run, it's all or nothing.

If you're just adding a class to the attributes array a template_preprocess hook would be sufficient, and stop you having to copy the entire thing, e.g.

function MYTHEME_preprocess_form_element(&$vars) { $vars['attrbiutes']['class'][] = 'another-class'; } 

If you need to add a wrapper around the outer element you can do something like this

function MYTHEME_form_element($vars) { $original = theme_form_element($vars); return '<div class="something">' . $original . '</div>'; } 

But if you need to add an extra attribute to an internal element of that theme function, you'll need to copy the whole thing over. PHP offers no way to pick a section of a function to run, it's all or nothing.

If you're just adding a class to the attributes array a template_preprocess hook would be sufficient, and stop you having to copy the entire thing, e.g.

function MYTHEME_preprocess_form_element(&$vars) { $vars['attributes']['class'][] = 'another-class'; } 

If you need to add a wrapper around the outer element you can do something like this

function MYTHEME_form_element($vars) { $original = theme_form_element($vars); return '<div class="something">' . $original . '</div>'; } 

But if you need to add an extra attribute to an internal element of that theme function, you'll need to copy the whole thing over. PHP offers no way to pick a section of a function to run, it's all or nothing.

Source Link
Clive
  • 168.5k
  • 19
  • 305
  • 338

If you're just adding a class to the attributes array a template_preprocess hook would be sufficient, and stop you having to copy the entire thing, e.g.

function MYTHEME_preprocess_form_element(&$vars) { $vars['attrbiutes']['class'][] = 'another-class'; } 

If you need to add a wrapper around the outer element you can do something like this

function MYTHEME_form_element($vars) { $original = theme_form_element($vars); return '<div class="something">' . $original . '</div>'; } 

But if you need to add an extra attribute to an internal element of that theme function, you'll need to copy the whole thing over. PHP offers no way to pick a section of a function to run, it's all or nothing.