Critical because it blocks a fully functioning form builder for D7 (core or contrib).
Almost all the core modules that affect the node form also need to be
updated so that their forms are separate from their implementations of
hook_form_alter(). Form builder needs to be able to render these
fields (such as Menu settings, Book settings, Taxonomy vocabularies,
etc.) separately from their parent hook_form_alter() implementations,
so this usually just means copying the existing form to a separate
function. This task can be done separately from all the other work on
Form Builder. There are dozens of examples and TODOs marked in the
current CVS code for Form Builder in each modules example
implementations (see the taxonomy.inc, menu.inc, upload.inc, node.inc,
etc.)
As an example, take path_form_alter() http://api.drupal.org/api/function/path_form_alter/7
copy and paste the code from there into a helper function, and just have path_form_alter() use that function rather than doing all the work itself.
The path example is also necessary for minor usability patches like #476290: Add path alias to taxonomy term edit so makes sense in itself.
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | 503780.patch | 52.98 KB | cweagans |
| #13 | upload.module.patch | 5.47 KB | seutje |
| #12 | taxonomy.module.patch | 6.92 KB | teezee |
| #11 | translation.module.patch | 5.5 KB | seutje |
| #10 | path.module.patch | 3.12 KB | seutje |
Comments
Comment #1
damien tournoud commentedI believe that we should go one step further, and make all those elements form_altered into the node form into proper FAPI #types.
Comment #2
gábor hojtsyMaybe not all cases would be logical as their own form elements, would they? Do we have a good list?
Comment #3
catchTaxonomy vocabularies we should just move into a helper function on the assumption that #491190: Provide a taxonomy term field type and #412518: Convert taxonomy_node_* related code to use field API + upgrade path get in.
Upload similarly because we have #391330: File Field for Core.
Path, menu and book probably make sense as elements - can't see those turning into fields any time soon, and at least menu and path are things which can/should appear in other places.
Can't think of any others which affect the node form off the top of my head.
Comment #4
seutje commentedQuick list of form_alter functions in core that affect the node form:
so I understand we're not touching the hook_form_node_type_form_alter right now, which are
and what should these helper functions be called? modulename_node_form_element?
Comment #5
gábor hojtsyComment #6
seutje commentedok, how's this?
not sure if the is a proper description for this
Comment #7
teezee commentedMoved contents of comment_form_alter() for extending node forms to separate function comment_node_form_element().
Will that do?
Comment #8
teezee commentedMoved code in menu_form_alter() to separate function menu_node_form_element().
Comment #9
seutje commentedMoved code in locale_form_alter() to separate function locale_node_form_element()
noticed that locale_form_alter takes $form_state as reference, I left it as it was, but I'm still unclear on why -> #503892: hook_form_alter() and hook_form_FORM_ID_alter() take $form_state as reference
Comment #10
seutje commentedMoved code in path_form_alter() to separate function path_node_form_element()
Comment #11
seutje commentedMoved code in translation_form_alter() to separate function translate_node_form_element()
same weirdness as described in [#503829]
Comment #12
teezee commentedMoved most of the code in taxonomy_form_alter() to (new function) taxonomy_node_form_element().
Comment #13
seutje commentedMoved the node form related code to separate function upload_node_form_element() and noticed that the node_type form code wasn't extracted to the upload_form_node_type_form_alter() yet, so I also did that as per #287178: Use hook_form_FORM_ID_alter() where possible and added some doxygen comments
Comment #14
seutje commentedComment #15
catchCould one of you roll these into a single patch?
Comment #16
cweagansAttached.
btw: patches should be made from the root of your Drupal tree -- not from the module folder that you are working on. A number of these were made from the modules/___ directory.
Comment #17
cweagansWoops.
Comment #18
catchThis patch looks like it introduces a new hook - hook_node_form_element() - but all these functions are called directly from hook_form_alter(), it's not a new hook at all.
That makes me a bit worried about the standardized naming as well in case it looks too much like a hook, probably it's OK though.
Comment #19
seutje commentedI understood that these will eventually be reusable hooks, but (at least right now) they also need to be called from the regular hook_form_alter, because the hook isn't invoked yet, but could easily be done
personally, I'm not that excited about the naming either, mainly because the name suggests that it only adds 1 element, where most core modules add more than 1 element so maybe hook_node_form_elements() would be better than hook_node_form_element()
Comment #20
damien tournoud commentedI think this is still pretty much important, but I'm not sure about the way forward. I would like to make those proper form elements, so that you can do:
Those elements would be expanded with a proper
#processfunction and could be used as-is by the form builder. What do everyone think?Comment #21
sun.core commentedWe definitely need a longer API clean-up phase for D8.
Comment #22
catchDowngrading all D8 criticals to major per http://drupal.org/node/45111
Comment #23
sunHow much of this issue/patch is still relevant today?
Comment #24
xjmOkay, looking at the form alters listed in #4 and in most cases locating their D7 equivalents:
book_form_alter()is now book_form_node_form_alter() and has a wonky "private" callback to construct the form that passes the$formarray by reference, D6-style: _book_add_form_elements()$formarray.taxonomy_form_alter()andupload_form_alter()no longer exist because their functionality is now part of the Field API.However, it's not clear to me why this is necessary. Clearly we have a working form builder in D7, contrary to the original post. Can anyone clarify?
Comment #25
berdirYes, I don't understand either why this is necessary.
@sun, can you clarify?
My guess is that you are referring to http://drupal.org/project/form_builder?
Comment #26
xjmBerdir and I agree that this is at most a nice refactor for reusability and code cleanliness, but it really doesn't seem to be major. Downgrading and tagging for a summary so we can get something more accurate than "Forms won't work in D7!" which is a bit anachronistic. :)
Comment #27
xjmOh, it's still a good novice task though. :)
Comment #28
sunMerely refactoring this code into individual functions instead of pure Form API callbacks isn't going to be sufficient and I don't see how that is going to improve the situation in any way. It's also not really clarified in this issue.
Instead, we should have a proper discussion for how to handle those entity form widget additions (of which some aren't really field_extra_fields) into a general pattern - ideally re-using generic (field/property) widgets and formatters, and possibly also upcoming theme components.
Given that form_builder seems to work without this, let's won't fix this issue.