Themes cannot have a preprocess function without a corresponding .tpl.php file

JohnAlbin - May 13, 2008 - 19:50
Project:Drupal
Version:7.x-dev
Component:theme system
Category:bug report
Priority:normal
Assigned:JohnAlbin
Status:patch (code needs work)
Description

Many times, sub-themes just need to tweak a variable in a tpl file and they don’t need to modify the tpl file's contents.

For example, if a sub-theme wants to modify the $submitted text, it doesn't need to modify the html/php in the base theme’s node.tpl.php.

Unfortunately, the auto-discovery phase of the theme registry building process first looks for tpl files in a theme and then for the corresponding preprocess functions. So if there isn't a tpl file, the theme registry building process won't look for a preprocess function.

No patch yet, but the way I envision this working is similar to the work-around that Zen 6.x-1.x has (#249532: Allow subthemes to have preprocess hooks without tpl files.). Grab the existing theme registry and loop through the known hooks (those that have tpl files), while looking for possible preprocess functions in the theme.

#1

Gábor Hojtsy - May 13, 2008 - 19:55

Hm, this might qualify as a D6 bug indeed.

#2

dvessel - May 13, 2008 - 20:26

This limitation is documented. A fix would be nice though.

Read the middle of this page in the list of notes:
http://drupal.org/node/223430

#3

JohnAlbin - May 13, 2008 - 20:42

Since the theme guide is amazingly accurate and based on the actual implementation (warts and all) and not based on the design, all the documented "limitations" fall into the "maybe this a bug" category. :-D

Let's see what the patch looks like and then decide whether this should be backported to D6.

#4

merlinofchaos - May 13, 2008 - 23:03

I am in favor of fixing this in D6 if the fix can be done without breaking the existing API, because it is a limitation that was not intended and causes quite a bit of acrobatics to get around.

#5

Arancaytar - July 1, 2008 - 06:40

Please, please, please put this in. In D7 certainly, and it would be nice in D6 as well, so we don't need to wait a year for the awesomeness.

#277063: The next generation of DHTML Menu

#6

Arancaytar - July 1, 2008 - 19:58
Status:active» patch (code needs review)

Here is a patch for D6.

I'd submit the D7 patch first, but I've tested this one.

#7

dixon_ - July 1, 2008 - 20:03
Status:patch (code needs review)» active

@Arancaytar: The patch is missing... ;)

#8

Arancaytar - July 1, 2008 - 20:58
Status:active» patch (code needs review)

And in this case I can't even blame d.o. While rolling it, I got caught up in something and actually forgot. :P

AttachmentSize
drupal-theme-preprocess-258089-8.patch1.3 KB

#9

Arancaytar - July 1, 2008 - 21:00

The patch is for Drupal 6, but succeeds on HEAD with offset. Still testing if it works too.

#10

Arancaytar - July 1, 2008 - 22:24

I've ported my new DHTML menu module to D7 for testing purposes, and it works. Unfortunately my server is incapable of running simpletest reliably.

#11

Arancaytar - July 4, 2008 - 16:34

I still don't know whether this patch will be allowed into Drupal 6 or will have to wait for Drupal 7...

#12

chx - July 7, 2008 - 14:50
Project:Drupal» Documentation
Version:7.x-dev»
Component:theme system» Customization and Theming Guide
Status:patch (code needs review)» active

This is a documentation issue not a code one. Functions should have no preprocess for performance concerns. http://www.lullabot.com/articles/overriding-theme-functions-in-modules for a way .

#13

merlinofchaos - July 7, 2008 - 20:07
Project:Documentation» Drupal
Version:» 7.x-dev
Component:Customization and Theming Guide» theme system
Status:active» patch (code needs review)

This has nothing to do with theme functions, it has to do with theme templates, chx.

#14

chx - July 8, 2008 - 04:35

<?php
@@ -596,7 +596,27 @@ function theme() {
   }
   if (isset(
$info['function'])) {
    
// The theme call is a function.
-    $output = call_user_func_array($info['function'], $args);
?>

Huh what? This has nothing to with theme functions???? I am confused.

#15

merlinofchaos - July 8, 2008 - 06:02
Status:patch (code needs review)» patch (code needs work)

chx: Arancaytar's patch is wrong, but that's no reason to bury the whole issue. The actual issue is about themes having preprocess functions but using an ancestor's template.

Arancaytar: Your patch is wrong. It shouldn't be intercepting theme functions. chx is right on that part; theme functions need to have the speediest route possible.

 
 

Drupal is a registered trademark of Dries Buytaert.