1

I have a custom Drupal 6 module, with a custom theme function. I have implemented hook_theme in my mymodule.module (main module file) as follows:


function mymodule_theme() {  
  return array(
    'mymodule_template_regions'   => array(
      'arguments' => array('template' => array()),
      'file'      => 'mymodule.theme.inc',
      'path'      => drupal_get_path('module', 'mymodule') . '/templates',
      'template'  => 'mymodule-template-regions',
    ),
  );
}

I have implemented mymodule_preprocess_mymodule_template_regions() in a file called mymodule.theme.inc, in the main module folder.

I have placed mymodule-template-regions.tpl.php in the templates subfolder inside my main module folder.

This all works fine when the cache is cleared. As soon as the page is refreshed after the initial cache clear, it stops working.

The offending line is line 696 of theme.inc in Drupal Core version 6.19, which states:


if (function_exists($preprocess_function)) {
  call_user_func_array($preprocess_function, $args);
}

When the cache is cleared, the mymodule_preprocess_mymodule_template_regions function exists, so it gets called because the 'if' statement yields TRUE. However, on each subsequent page request, the function does not exist. I presume this is because, for whatever reason, mymodule.theme.inc is not being included.

This is where my knowledge of Drupal breaks down, as I'm unaware of what else is going on here and how to track down why the function is not being included. It looks like the theme registry is still aware of mymodule_preprocess_mymodule_template_regions, but that it's simply not being called because it's not included.

1 Answer 1

2

Drupal is looking to include the following file:

drupal_get_path('module', 'mymodule') . '/templates' . '/mymodule.theme.inc'

but, you say that you've put it in the main module folder, here:

drupal_get_path('module', 'mymodule') . '/mymodule.theme.inc'

So Drupal isn't going to include the file on subsequent calls to the theme function. So, you might want to move your include.

You can see this from how your hook_theme is processed in: _theme_process_registry

1
  • 1
    The actual problem is that I'm an idiot. But more specifically it's that the file is called 'mymodule.theme' and not 'mymodule.theme.inc' as was written in my code. Still, I appreciate the answer as it pointed me in the right direction for sure. Commented Apr 14, 2011 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.