There's a bug in theme_node_form() where all of the node's form elements are rendered in the first call to form_render(). The two subsequent calls do not output anything.

You can see this by viewing the source of a node form and looking for <div class="authored"> and <div class="options"> - both of these <divs> are empty.

I found this bug, whilst trying to theme a node form. I am using PHP 5.0.5, Apache 2.0.55 and MySQL 4.1.15.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Egon Bianchet’s picture

Version: 4.7.0-beta4 » 4.7.0

Still valid ...

chx’s picture

Status: Active » Needs review
FileSize
939 bytes
drumm’s picture

Status: Needs review » Needs work

This removes the authoring information and puts the publishing options at the bottom.

drumm’s picture

Or could we remove the divs and put a class on each fieldset?

Jaza’s picture

Title: Theme node form bug » Admin form fields not getting rendered at bottom of node form like they should
Component: forms system » node system
Status: Needs work » Needs review
FileSize
2.27 KB

New patch that fixes a number of issues with the theme_node_form() function:

- calls form_render() on the 'authoring information' and 'publishing options' elements BEFORE running the catch-all form_render() - if it's done after (as it was previously), the call is useless and will never yield any output.
- wraps an isset() check around elements that may not always be displayed, depending on the privileges of the user. Also an empty() check before outputting the 'admin' div. This gets rid of the empty divs that were getting outputted.
- Places the admin controls at the bottom (which is what I assume the previous code was trying to do, but was failing to actually do), and the submit buttons at the very bottom.
- Puts in a bit of comments explaining that the code's purpose is to move certain fields to the bottom of the form - took me a while to figure out that this is what was trying to be achieved, it wasn't really that obvious.

drumm’s picture

Status: Needs review » Needs work

This patch has Mac newlines on the changed code (and some extra), but Unix newlines on the unmodified code. This makes the patch larger (some lines have only the line ending changed) and we wouldn't want the inconsisntent newlines committed.

Jaza’s picture

Status: Needs work » Needs review

Newlines are now all unix-style, unnecessary lines are gone. Apart from that, same patch.

Jaza’s picture

FileSize
1.8 KB
Jaza’s picture

Assigned: Unassigned » Jaza
FileSize
2.09 KB

Added a whole heap of new-lines (i.e. \n) to the outputted HTML, and added a missing </div> at the end.

Dries’s picture

Why is that function called 3 times to begin with? What is the purpose of the two subsequent calls?

Jaza’s picture

Uhhh.. it's not called three times, it's only called once. You mean theme_node_form(), right? As far as I can tell, it's just called by drupal_get_form(), which gets called in the node_form() function.

Dries’s picture

The original report reads: "There's a bug in theme_node_form() where all of the node's form elements are rendered in the first call to form_render(). The two subsequent calls do not output anything.". It's what made me believe it is called more than necessary.

Other than that, you're patch makes sense! Please set to RTBC (and I'll commit it) if we can ignore the comment above. Thanks.

Jaza’s picture

Status: Needs review » Reviewed & tested by the community

Ahh.. yes, form_render() is getting called three times in the original code, AND in this patch. However, the "two subsequent calls [that] do not output anything" in the original code, are now (i.e. in this patch) being called first (before the third form_render() call, which is a catch-all call), and so in this patch they DO output something. Hence, the bug is fixed.

I'm pretty confident that this patch is ready to go in (just tested, still applies and works fine), so RTBC.

Dries’s picture

Committed to CVS HEAD. Needs to be backported to 4.7.0, IMO.

killes@www.drop.org’s picture

Status: Reviewed & tested by the community » Fixed

applied

Anonymous’s picture

Status: Fixed » Closed (fixed)