Only override part of a theme function In Drupal 7 you can take a theme function and override it.

For example if I want to override theme_form_element, I would place it in  my template.php as MYTHEME_form_element.

The only problem is that I then have to copy the entire theme function into my template.
For example, for theme_form_element, there is over 60 lines of code.

This seems overkill, if I only want to do something simple as add a class to the attributes array. 

Is there any way to only include the part of the theme function I want to override and tell Drupal to refer to the rest of the built in function?
If you need to change the content of the variables passed to the theme function, then you can simply implement a preprocess function for that theme, which in Drupal 7 is invoked for every theme function, including the ones not using a template file.
In the case of theme_form_element() the preprocess function for your theme is MYTHEME_preprocess_form_element().

You could also avoid duplicating the code of theme_form_element(), and call it before, but in that case you should call it directly as theme_form_element(), not as theme('form_element') (which would cause an infinite loop).

The problem with theme_form_element() is that it doesn't use $element['#attributes']['class'] to set the attributes of the form element. It uses a local variable that is initialized with the following code, which passes its value to drupal_attributes().

  $attributes['class'] = array('form-item');
  if (!empty($element['#type'])) {
    $attributes['class'][] = 'form-type-' . strtr($element['#type'], '_', '-');
  }
  if (!empty($element['#name'])) {
    $attributes['class'][] = 'form-item-' . strtr($element['#name'], array(' ' =&gt; '-', '_' =&gt; '-', '[' =&gt; '-', ']' =&gt; ''));
  }
  // Add a class for disabled elements to facilitate cross-browser styling.
  if (!empty($element['#attributes']['disabled'])) {
    $attributes['class'][] = 'form-disabled';
  }
  $output = '&lt;div' . drupal_attributes($attributes) . '&gt;' . "\n";


To add a new class to the form element, you have two alternatives:


Copying the code from theme_form_element() to your theme function, and editing it
Call theme_form_element() from your theme function, and add a new class to the output returned from theme_form_element() using preg_replace().