Form elements with the same weight are sorted randomly each page load. This primarily effects core in regards to filter formats - our node types have a Body of 0, and our filter formats do as well. This causes, randomly, the filter format to appear ABOVE the Body. There's also the danger of multiple textareas (each with their own filter format), all with the same weight: the chaotic sorting creates a situation where you have no idea which input filter applies to which textarea.
There were lots of possible ways to solve this, including a new form element type (textarea_filtered), a new element attribute (#filter => 1), unique weights (0.4535), alphabetical sorting with names like "body" and "body_filter", and so forth. Ultimately, chx and I decided that using FAPI containers, or "branches", would be the simplest solution, and also utilizes what FAPI already provides. Branches are containers, just like fieldsets (only non-visual), and the items in the branch sort according in their own weight table. Thus, to ensure that the textarea and the filter always appear that way visually, without conflicting with any other same weight elements, we just give all our filterable textareas in core their own branch, which includes ONLY the Body and the Input Filter.
The patch also cleans up some double newlines.
| Comment | File | Size | Author |
|---|---|---|---|
| _filterweight.patch | 10.45 KB | morbus iff |
Comments
Comment #1
Crell commentedI was just running into that bug myself.
Long-run, I think a textarea_filtered form element makes more semantic sense to me. That way it would also be easier to handle it with textarea plugins. For the time being, though, this looks like a nice and simple solution that works. Yay for the Form API. :-)
Applies cleanly, code looks good, Fixes a bug, and the HTML output is unchanged as far as I can see. I like. Setting RTC.
Perhaps something should also be added to developer docs so that contrib authors know this trick as well?
Comment #2
morbus iffCrell: thanks for the review. Currently, textarea_filtered isn't even possible, as it'd require two #values - one for the textarea, and one for the value of the filter format. That currently isn't possible within FAPI. (At Dries and a few other folks request, I set out to *make* textarea_filtered, and chx and I ran into this problem.)
Comment #3
dries commentedCommitted to HEAD. Thanks.
Comment #4
(not verified) commented