Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
forms system
Priority:
Critical
Category:
Task
Assigned:
Reporter:
Created:
1 Jan 2009 at 00:09 UTC
Updated:
15 Oct 2009 at 20:01 UTC
Jump to comment: Most recent file
With this patch, forms are returned before being drupal_render'd from drupal_get_form... Makes variable output formats a whole lot easier for forms.
Depends on #351235: hook_page_alter().
Note: DOES NOT FULLY WORK YET. I'M JUST POSTING PROGRESS
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | no_render_in_fapi.patch | 19.83 KB | moshe weitzman |
| #16 | no_render_in_fapi.patch | 16.99 KB | moshe weitzman |
| #13 | no_render_in_fapi.patch | 14.8 KB | moshe weitzman |
| #8 | dont_drupal_render_forms_0.patch | 16.56 KB | dmitrig01 |
| #4 | dont_drupal_render_forms.patch | 17.82 KB | dmitrig01 |
Comments
Comment #1
dmitrig01 commentedMoving to a more appropriate status.
Comment #2
chx commentedyou can get a lot further by using a simple regexp replace
preg_replace('/drupal_get_form((?:[^()]++|\((?1)\))+)/U', 'drupal_render(\0)',to wrap the standalone drupal_get_form calls in a drupal_render.Edit: I mean apply this to Drupal modules themselves.
Comment #3
dmitrig01 commentedOk, thanks
Comment #4
dmitrig01 commentedTests don't work on my computer, however this patch is 100% ATM.
Comment #5
dmitrig01 commented#351235: hook_page_alter() is in (YAY!!)
Comment #6
dmitrig01 commentedComment #8
dmitrig01 commentedLet's try this one
Comment #10
dmitrig01 commentedwill inestigate tommorow
Comment #11
moshe weitzman commentedThanks for reviving this. Decided to take a look and see how it is going ...
"for that it's necessary to use drupal_render". append parens to drupal_render() so it hyperlinks in api docs.
at first blush, this looks like it can be a regular menu callback that returns an unrendered array: locale_translate_seek_screen
user_admin() does not look right. you mix $page and $output. That function is a throwback to pre_fapi. Not in scope for this patch but a refactor is needed.
Comment #12
chx commentedWith the page array we surely can do a lot with this... I see search.pages.inc converted for that, can we get the rest converted too?
Comment #13
moshe weitzman commentedHere is a complete patch which does just as dmitrig01 proposed - remove drupal_render() from FAPI. In Drupal7, menu callbacks are supposed to return arrays so calling drupal_render() on a form is not needed nor desired. Lets leave this content in arrays form and just let it render with the rest of the page.
This patch adds a few drupal_render() calls which should eventually be removed when those menu callbacks refator to return an array. There is no need to do that much refactoring in this patch.
Comment #14
chx commentedI only have one question. Have you checked that everything you changed is covered by a test?
Comment #16
moshe weitzman commentedfixed install. lets let the bot find more stuff.
tabledrag is still funny looking.
Comment #18
moshe weitzman commentedFixed test errors. /me hugs the test suite and test bot. How did we live without thee?
Reminder. devel.module has an option to pretty print the $page array during hook_page_alter(). You might want to use that to browse how a form page looks (e.g. admin/build/block).
Comment #19
ejort commentedsubscribe
Comment #20
merlinofchaos commentedI find this syntax to be kind of ugly:
I understand why we want drupal_get_form to return unrendered forms for the page, but I'm hesitent to do it at the expense of making drupal_get_form complex. drupal_get_form is intentionally meant to be kept very simple, and if you need complexity you move to drupal_build_form() where you have more power.
Maybe we should use two functions. drupal_get_form() and drupal_render_form()? I'm unsure if this is really the right answer but it's something we should give some thought to.
Comment #21
moshe weitzman commentedThanks for the review.
I started with a two function solution where where we have a drupal_get_form that is unrendered and a rendered version as you suggest. I found it to be awkward, and also not backwards compatible. But more importantly ...
The ugly code you mention is temporary. We should *not* be using drupal_render() in module code. Modules need to pass back arrays, not strings. There are very few legitimate uses for drupal_render() beyond drupal_render_page(). Just a few theme functions that need to ccarefully control their output. I added some drupal_render() calls because refactoring spaghetti like comment module is beyond the scope of this patch. I'll do it, but not here.
Comment #22
dries commentedUnlike Earl, I think that
drupal_render(drupal_get_form('locale_translation_filter_form'))is actually quite elegant, and more readable and predictable than what we have right now.What's missing though, is the motivation for this patch. Is it just clean-up, or does it open certain doors?
Comment #23
moshe weitzman commentedThe motivation is to get as many pages as possible to play nicely with the new hook_page_alter(). With this patch, all pages whose page callback is drupal_get_form() will now stay in array form when they go through that hook. Without this patch, all these pages are already rendered HTML by this time.
One might use hook_page_alter() to split the form into multiple page regions. Thats not possible with hook_form_alter().
Comment #24
dries commentedThanks Moshe, that is what I expected. I think this should go in, but I'm waiting for the test bot. I can run the tests myself, if necessary.
Comment #25
moshe weitzman commented@Dries - the test bot is woefully behind, AFAICT. See http://testing.drupal.org/pifr/status. Also, results are apparently not being reported back to drupal.org.Would be wonderful if you ran those tests.
Comment #26
moshe weitzman commentedOh nice. test bot has marked this patch green again.
Comment #27
dries commentedCommitted to CVS HEAD. Please update the upgrade instructions in the handbook, and mark this 'fixed' after. Thanks all!
Comment #28
moshe weitzman commentedupgrade docs authored
Comment #30
donquixote commentedIt's probably too late, but I would have done it in a different way, to make module migration to D7 easier, and allow drupal_get_form to remain being used in hook_menu:
- have drupal_get_form behave as it used to.
- split the function internally, so it does something like:
Would have been easier, and could even be used in D6. drupal_get_form() could still be used in hook_menu. And one could use the other function "drupal_get_form_build" (or choose a better name) where you need the unrendered form array.
In fact I did this in a custom D6 module for myself, but it feels stupid having to copy core things.
(this is what I wanted to report before I found this thread)