[development] Drupal 7 API change in hook_theme()

Angela Byron drupal-devel at webchick.net
Fri Oct 23 22:39:59 UTC 2009


During the Drupal 7 development cycle, we made a couple of changes to  
theme functions, notably:

1. They now all take a standardized array of variables instead of an  
arbitrary list of parameters (see http://drupal.org/update/modules/6/7#theme_changes) 
.

2. When passing in a renderable element (such as forms, pages,  
content, etc.), you can pass in parameters via #properties  (see http://drupal.org/update/modules/6/7#poundtheme) 
.

Unfortunately, these two changes clash with one another in the case  
where you pass in a single non-renderable argument to your theme  
function, and we didn't catch this until the couple days or so before  
code freeze. It then took a few additional days to get an acceptable  
fix together. (http://drupal.org/node/600974 if you're curious about  
the backstory here.)

Therefore, we have the first of what is *hopefully* a very short  
list ;) of Drupal 7 API changes post-code freeze. Please be advised  
that if your D7 module defines a hook_theme(), you need to change it  
in the following way:

1. Where you used to say 'arguments' => array('whatever' => NULL,  
'whatever' => NULL), you now say 'variables' => array('whatever' =>  
NULL, 'whatever' => NULL)

2. In the case where you're passing in a renderable element to your  
theme function (such as the case of a form theme function), instead of  
specifying it in the list of variables, you'll simply add: 'render  
element' => 'form' and omit the 'variables' line altogether.

Sorry for the hassle, but believe me, this is a *much* better  
situation than not being able to have theme functions with one  
argument. :P And thanks so very much to those who've embraced #D7CX  
and have started porting your modules already!

-Angie



More information about the development mailing list