[development] theming in D7

Bob Hutchinson hutchlists at midwales.com
Sun Oct 24 16:45:07 UTC 2010


On Saturday 23 October 2010, Earl Miles wrote:
> On 10/22/2010 1:56 PM, Bob Hutchinson wrote:
> > In D7 I get somewhat different behaviour:
> > 
> > If I do not create an entry in the theme registry, all works as expected,
> > but if I do, things start to behave oddly.
> > 
> > function mymodule_theme() {
> > ....
> > 
> >     'mymodule_thingy_form' => array(
> >     
> >       'variables' => array(
> >       
> >         'form' => NULL,
> >       
> >       ),
> >     
> >     ),
> 
> In D7 the above should actually be:
> 
>      'mymodule_thingy_form' => array(
>        'render element' => 'form',
> 
> > ....
> > }
> > and create a function
> > function theme_mymodule_thingy_form($variables) {
> > 
> >   $form = $variables['form'];
> >   $output = drupal_render($form);
> >   return $output;
> > 
> > }
> 
> You should use either render() or drupal_render_children() rather than
> drupal_render(). So far as I could figure out, drupal_render() should no
> longer be used inside theme functions. You use render() to render a
> specific element, and drupal_render_children() to render all the
> children but NOT the element (which is what you want when attempting to
> render $form since that is currently being rendered).

I ran some trials using form_example from http://drupal.org/project/examples
I found that indeed I should not use drupal_render()  inside theme functions, 
drupal_render_children() works fine.
I also found that using drupal_get_form() within a function (as opposed to in 
a menu) requires the output of drupal_get_form() to be run through render(), 
otherwise the form is not complete. The theme (defined with 'render element') 
is picked up automatically, the same as it is when calling  drupal_get_form() 
directly in a menu $item.

Thanks for your help.

-- 
-----------------
Bob Hutchinson
Midwales dot com
-----------------


More information about the development mailing list