Losing custom #theme settings set in hook_field_widget_form after an error I have defined a custom field in a custom module.  The new field applies a custom font to the options, and I have run into an issue with the widget form after an error. I have implemented hook_field_widget_form in a manner similar to the following:

mymodule_field_widget_form(&amp;$form, &amp;$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  switch ($instance['widget']['type']) {
    case 'mymodule_custom_widget':
      $element += array(
        '#theme' =&gt; 'mymodule_checkboxes',
      );
      break;
  }
  return $element;
}


mymodule_checkboxes and mymodule_checkbox have been defined in hook_theme as follows

function mymodule_theme() {
  return array(
    'mymodule_checkboxes' =&gt; array('render element' =&gt; 'element'),

    'mymodule_checkbox' =&gt; array(
      'template' =&gt; 'mymodule_checkbox',
      'pattern' =&gt; 'mymodule_checkbox__',
      'arguments' =&gt; array('element' =&gt; NULL),
    ),
  );
}


To put it shortly, theme_mymodule_checkboxes calls theme(array('mymodule_checkbox'), array('element' =&gt; $current_element)); on every element in the #options array.

Everything is working great on the initial load of the form, the theme_mymodule_checkboxes function is called and the options are output using my custom template (the template isnt really necessary, I plan on replacing it with a theme function but havent gotten around to it. I don't think that particular oversite has any bearing on this issue but I may be wrong).  After I submit the form with an error - say I don't input a title or some such - the field is rendered using the default checkboxes theme.

Is there some hook I am missing in which I can define the default theme for the form widget before hook_field_widget_form?  One that hopefully fires even after a form fails validation?  I think I might be able to require a form rebuild in my custom field validation, but that forces extra work, and I would like to avoid that.
This one turned out to be a fairly simple fix. I had theme_mymodule_checkboxes living in mymodule.admin.inc which was not being included on every page. Moving the function to the mymodule.field.inc which is specifically included in the module file caused the theme function to be included and fixed the error.

Many thanks to the drupal user Ayalon who found this fix.