Custom theme function not being called? I'm building a Drupal 7 module to create a bespoke field type. I've implemented all the required hooks. My hook_field_formatter_view() function looks like this:

function MYMODULE_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();

  switch ($display['type']) {
    case 'default':
      foreach ($items as $delta =&gt; $item) {
                $element[$delta] = array(
                  '#theme' =&gt; 'test',
                  '#item' =&gt; $item,
                );
      }
      break;
  }

  return $element;  
}


I've then defined the theme() function below:

function theme_test($variables) {
    return '&lt;h1&gt;Hello World&lt;/h1&gt;';
}


But when I view the page nothing is output. If I look at the recent log entries I see this message:

Theme key 'test' not found.

If I change my MYMODULE_field_formatter_view render array '#theme' value to a built in theme function like 'item_list' it works. But for some reason my custom theme function is not being picked up.

I've rebuilt the theme registry hundreds of times as well as cleared the caches.
You probably have not defined your theme hook in hook_theme().

The Using the theme layer section of the Development handbook has an in-depth discussion about this.