I found that in one specific case, path_to_theme() points to the modules directory. To illustrate, add this into your theme.inc file.
function drupal_discover_template($suggestions, $extension = '.tpl.php') {
global $theme_engine;
// Loop through any suggestions in FIFO order.
$suggestions = array_reverse($suggestions);
foreach ($suggestions as $suggestion) {
//// ADD THIS NEXT LINE ////
print var_dump(path_to_theme() .'/'. $suggestion . $extension);
if (!empty($suggestion) && file_exists($file = path_to_theme() .'/'. $suggestion . $extension)) {
return $file;
}
}
}
Then get into a page that suggests a template such as example.com/forum.
This only happens when a suggestion is made from a "template_preprocess*" variable function inside a *module*.
This doesn't happen when the suggestion is made from theme.inc. 'page' or 'node' suggestions behave as expected.
Comments
Comment #1
moshe weitzman commentedi ran into a similar problem in devel.module. see a code comment in its template log feature.
Comment #2
dvessel commentedA correction..
The suggestions are made from theme.inc but those hooks are registered by the theme. That's why they worked.
Comment #3
merlinofchaos commentedI found that in one specific case, path_to_theme() points to the modules directory. To illustrate, add this into your theme.inc file.
This is actually not incorrect. path_to_theme() was modified to point to whatever 'theme' is currently active. This was necessary to allow true inheritance of themes.
Let's take an example: forums.tpl.php
I have a theme, 'zen'.
I have another theme, 'foo', whose base theme is set to 'zen'.
Now, assuming forums.tpl.php has some subsidiary files it needs (it doesn't, but let's assume it does; this is most likely going to be images of some sort), we normally expect these files to be in the same directory. That's the normal use of path_to_theme(), in fact.
If I drop forums.tpl.php + forum_image.png into 'zen', my actual theme is 'foo'. I can't have path_to_theme() actually point to 'foo' or it won't be able to find forum_image.png. So path_to_theme was modified to vary where it points based upon which theme is currently active.
That means that if 'forums.tpl.php' lives in the modules/forum, that's where path_to_theme() is going to point while that function is running. Interestingly...That is *correct*, because a module should never be referring directly to a theme's files.
However, there IS a bug here, and that has to do with suggestions. Suggestions are only loaded from the current path_to_theme. What we need to do is collect the theme paths and have the suggestion finder search all of the possible directories for suggestions.
Patch forthcoming.
Comment #4
merlinofchaos commentedHere's a patch. I regret that I have not tested this very much, but I want to make this available to try and see.
Comment #5
dvessel commentedThere was a small error preventing it from doing its job. Here's a fix, a few minor doc changes to drupal_discover_template and the suggestions now follow where the base template actually exist.
Before, a general $path was set so when a template file exists in a sub-directory inside the theme, it didn't follow the base template. It now follows the the main template where ever its located.
fyi, .tpl files can now exist in sub-directories in the theme thanks to drupal_discover_template(). Before this patch, all the suggestions has to be located in the base level of the theme.
Fully tested. the order of their discovery is as expected.
Comment #6
dvessel commentedWhoops, I mean drupal_find_theme_templates() not drupal_discover_template().
btw, I tested this with sub-themes too. The discovery of the suggestions cascade as expected all the way down into the module.
Comment #7
merlinofchaos commentedI think this is ready go to, then.
Comment #8
gábor hojtsyLooks logical. Thanks, committed!
Comment #9
(not verified) commented