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 => $item) {
$element[$delta] = array(
'#theme' => 'test',
'#item' => $item,
);
}
break;
}
return $element;
}
I've then defined the theme()
function below:
function theme_test($variables) {
return '<h1>Hello World</h1>';
}
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.