Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#9 | theme_node_form_2.patch | 2.09 KB | Jaza |
#8 | theme_node_form_1.patch | 1.8 KB | Jaza |
#5 | theme_node_form_0.patch | 2.27 KB | Jaza |
#2 | theme_node_form.patch | 939 bytes | chx |
Comments
Comment #1
Egon Bianchet CreditAttribution: Egon Bianchet commentedStill valid ...
Comment #2
chx CreditAttribution: chx commentedComment #3
drummThis removes the authoring information and puts the publishing options at the bottom.
Comment #4
drummOr could we remove the divs and put a class on each fieldset?
Comment #5
Jaza CreditAttribution: Jaza commentedNew 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.
Comment #6
drummThis 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.
Comment #7
Jaza CreditAttribution: Jaza commentedNewlines are now all unix-style, unnecessary lines are gone. Apart from that, same patch.
Comment #8
Jaza CreditAttribution: Jaza commentedComment #9
Jaza CreditAttribution: Jaza commentedAdded a whole heap of new-lines (i.e.
\n
) to the outputted HTML, and added a missing</div>
at the end.Comment #10
Dries CreditAttribution: Dries commentedWhy is that function called 3 times to begin with? What is the purpose of the two subsequent calls?
Comment #11
Jaza CreditAttribution: Jaza commentedUhhh.. 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.
Comment #12
Dries CreditAttribution: Dries commentedThe 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.
Comment #13
Jaza CreditAttribution: Jaza commentedAhh.. 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.
Comment #14
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Needs to be backported to 4.7.0, IMO.
Comment #15
killes@www.drop.org CreditAttribution: killes@www.drop.org commentedapplied
Comment #16
(not verified) CreditAttribution: commented