theme() function can not find my hook_theme() patterns

emackn - March 13, 2009 - 15:28

I'm working on a custom reporting module, and running into trouble with getting patterns from my hook_theme() entries to be found by the theming layer, i.e. theme().

Basically, all i'm doing is building some data and then trying to render that same data in different formats based on the data type (xml, csv, html, etc). I'm trying to do the same thing views does with its different templates, but I couldn't find any clues in the views source. The only template that is found is the one defined by the 'template' attribute, which also happens to be the key of the hook.

Here's my hook_theme() in the report manager.

<?php
/**  $class looks like this
Array
(
    [title] => HIR By Commodity
    [class] => hir_by_commodity_report
    [arguments] => Array( [set] => Array(...) )
    [#module] => hir_reports
)
**/
 
function dcd_reports_theme($existing, $type, $theme, $path)
  {
   
$classes = _reports_providers();
   
$hooks = array();
       
    foreach (
$classes as $class) {
     
$function = $class['#module'] .'_dcd_report';
     
$template = str_replace('_', '-', $class['class']);
     
$path = drupal_get_path('module', $class['#module']);
     
$args = $class['arguments'];
     
     
$hooks[$class['class']] = array(
       
'arguments' => $args,
       
'pattern' => $class['class']."__",
       
'path' => $path,
       
'template' => $template,
      );
    }
   
    return
$hooks;
  }
?>

The report providers are separate modules, but are siblings under modules, not under my main reporting module.

Then I render, defined by each report class.

<?php
protected function render($display_type) {   
    if(
$display_type == 'xml') {
     
// for testing use return, change to echo when this starts working.
      // also tried passing in an array of templates, that didn't work, and why would I need to do that if I defined a pattern?
     
return theme( get_class($this) .'__'. $display_type, $this->results);
    } 
    else if(
$display_type == 'chart')
      return
theme(get_class($this) . '__' . $display_type, $this->results);
    else
      return
theme(get_class($this), $this->results);
  }
?>

Here is a screenshot of what appears in my theme registry for one of the reports,
http://img155.imageshack.us/img155/5784/picture1xnh.png

My gut tells me that I'm missing something simple. Any suggestions?

Use the devel module to take

mattyoung - March 13, 2009 - 16:25

Use the devel module to take a look at what's in the theme registry. Are the hooks you define there?

The image shows my

emackn - March 13, 2009 - 17:20

The image shows my theme_registry.

Not looking in module for patterns

febbraro - March 13, 2009 - 20:18

What is seems like is happening (I worked with @emackn on this) is that it wont look for patterns in your module directory (even though you put it in the hook_theme 'path' key) Patterned template seem to only be expanded/searched/included if they are found in your theme. The one way we found around it is to also register a preprocess function and in that specify a template suggestion (thus removing the need for a pattern) however this does not seem like the right thing to do.

take a look at this:

mattyoung - March 13, 2009 - 23:04

take a look at this: http://shellmultimedia.com/articles/hookthemeregistryalter-advanced-temp...

"So, the trick is to convince the registry that your module is a theme."

Try that and see if it work?

 
 

Drupal is a registered trademark of Dries Buytaert.