When a form makes use of the form storage it's impossible to set a redirect when the form is finally finished. The only way to achieve a redirect currently is to unset the storage, which is bad as modules won't find the data there any more. Also an explicitly set redirect shouldn't be ignored.
-> This fix makes it possible to use the form storage for any easy multistep form workflow for editing entities - see http://drupal.org/node/367006#comment-2272166. Once the workflow is finished the redirect target can be set while any module adding submit handlers still finds the entity in the storage as usual.
patch attached.
Comment | File | Size | Author |
---|---|---|---|
#47 | drupal.form-rebuild-storage-fix.patch | 3.33 KB | sun |
#45 | form.state_.storage.patch | 1.12 KB | Anonymous (not verified) |
#39 | form.state_.storage.patch | 894 bytes | Anonymous (not verified) |
#33 | drupal.form-storage-rebuild.32.patch | 5.64 KB | sun |
#12 | form_storage_all-12.patch | 10.06 KB | effulgentsia |
Comments
Comment #1
sunIn light of #583730: How many ways are there to cache a form?, I'd really prefer to remove the _entire_ caching + rebuilding magic around 'storage'. Not just rebuilding.
Comment #2
fagoI agree that the caching logic needs a cleanup (+ docs!) -> see my post at the other issue. But I don't think this is important here - the question is should storage auto-turn on 'rebuild' like now?
Well this would be changing more of the "documented" behaviour, but I agree it makes sense. That way altering modules can safely use the storage without changing the way the form works - so I'd be happy with that too. However still using storage would turn on caching.
Comment #3
fagook, here is an updated patch that makes using form storage not magically affecting the form workflow. Thus if you want the form to rebuild, you have to specify that.
-> That way altering modules can safely use the storage without changing the way the form works and modules can use storage by default without hassle.
Using storage by default has the huge benefit of your form being able to work with multiple steps even if you don't need it initially. -> related issue: #634984: Registration form breaks with add-more buttons
Comment #4
fagoComment #6
fagoadded missing rebuild for module uninstalling
Comment #7
sunI love you. :)
This comment needs work.
This review is powered by Dreditor.
Comment #8
sunBetter title.
Comment #9
fago:)
I improved the comment.
Comment #10
sunCan we also add the two properties to the PHPDoc of drupal_build_form() ? Neither 'storage' nor 'rebuild' is mentioned there currently.
Comment #11
sunSeems like this one is a real road-block for #367006: [meta] Field attach API integration for entity forms is ungrokable. Since we really need to quickly move forward, bumping to critical.
Comment #12
effulgentsia CreditAttribution: effulgentsia commentedYes, yes, yes!! Thank you for this issue! I'm completely in favor. The whole concept of form rebuilding and storage is complex and takes a while for a new developer to understand, and by decoupling the two concepts, it removes a lot of WTFs. The only downside I can see is people used to building multistep forms by just setting $form_state['storage'] will now need to also set $form_state['rebuild']. But, they can stop unsetting $form_state['storage'] on the last step, so it's trading one extra line of code needed with one line saved, so no net change to overall difficulty. And, this way makes more sense. I'm sure webchick would have preferred it if this change got committed and documented before API freeze, because now, module developers who've begun porting their modules to D7 will need to be notified about this. However, this only affects module developers who build multistep forms, and the level of Drupal expertise needed to do that is high enough, that these same developers will quickly understand the change, and even if they missed the notification, they'll have the debugging skills to figure it out.
This patch includes the documentation requested in #10, changes a documentation line from
If $form_state['rebuild'] is TRUE is populated
toIf $form_state['rebuild'] is TRUE
, and replaces all instances of "multi-step" with "multistep", because let's set a standard on how that's spelled that we can use when documenting how multistep forms work.Comment #13
sunPlease revert to "multi-step", and also rename "multi-part" to "multi-step" ;)
Not sure why we are yelling "not" here. So while being there, let's also fix that ;)
I'm on crack. Are you, too?
Comment #14
moshe weitzman CreditAttribution: moshe weitzman commentedIMO it is important to get this simplified so more module devs grok multistep and we can stop calling upon eaton to write a blog post about how to do multistep in Drupal x. I can't imagine this change will affect more than one or two modules (if that) so +1 for a code freeze exception here.
Comment #15
yched CreditAttribution: yched commentedNote that the changes around $form_state['storage'] and ['rebuild'] that are currently in the air might break some edge cases around batch API and multistep forms. This can be fixed afterwards and shouldn't hold this patch IMO, but we'd need the batch API tests added in #629794: Scaling issues with batch API sooner rather than later ;-).
Comment #16
sunJust to clarify in advance: This is no code freeze exception. It's a critical bug fix and we need to do this API change to make D7 work. #635552: [meta issue] Major Form API/Field API problems contains an overview and discussion of all related issues around this topic.
Comment #17
effulgentsia CreditAttribution: effulgentsia commentedReview in #13 is minor stuff related to comments, so doesn't affect RTBC state of this issue, but @sun: there's a bunch of other places within core that spell it "multistep". Are you suggesting they all be changed to use "multi-step", or are you suggesting to just remove hunks from this patch and let the inconsistency remain?
Comment #18
sunI was under the assumption that "multi-step" is the proper term, or at least, being used everywhere else.
Anyway, totally unimportant here. No reason to hold off this patch.
Comment #19
Dries CreditAttribution: Dries commentedI committed #583730: How many ways are there to cache a form? which might require this patch to be rerolled. I asked for a re-test.
Comment #22
yched CreditAttribution: yched commentedHEAD is broken - I got those two failures on a local HEAD, and so does http://drupal.org/node/629794#comment-2280216
Comment #23
yched CreditAttribution: yched commentedHEAD fixed - requiring re-test
Comment #25
effulgentsia CreditAttribution: effulgentsia commentedSo, this is RTBC then, yes?
Comment #26
effulgentsia CreditAttribution: effulgentsia commentedI apologize for poor clarity in #25. It's not a question. Yes, this is RTBC, as it was in #18. Everything from #19 to #24 was noise due to HEAD breakage unrelated to this issue or patch. It would be very helpful for this to land or have concerns raised quickly, as many other FAPI issues await it (#635552: [meta issue] Major Form API/Field API problems).
Comment #27
webchickI'd like to see an eaton or a chx on this issue.
Comment #28
effulgentsia CreditAttribution: effulgentsia commentedMakes sense to have either or both of them weigh in.
@chx: In #635552-8: [meta issue] Major Form API/Field API problems, you ask:
Please see this issue's description and comment #3 as well as the conversation in #635552: [meta issue] Major Form API/Field API problems. A summary of some of the reasons:
Comment #29
yched CreditAttribution: yched commentedPoint 3 is a little misphrased.
The 'add more' button de-facto makes any form where it appears multistep - i.e needs to support incoming form values from a previous state. That's to avoid "change node title, hit 'add more' for field_foo, the title input is reset" in non-JS mode.
"if the fieldable entity doesn't use a multistep form", then it's bugged. #367006: [meta] Field attach API integration for entity forms is ungrokable is about making the job of fieldable entities easier. And that involves using $form_state['storage'], which shouldn't *necessarily* mean the form is going to be rebuilt (if I just change node title and Save).
Comment #30
fago>And that involves using $form_state['storage'], which shouldn't *necessarily* mean the form is going to be rebuilt.
Yep, this an important point. So we can use $form_state['storage'] in any case, which then is enough to have your form working with multiple steps. This way it's not only easy to turn a single step form into multiple steps later on, but also the form won't break if someone alters it and introduces multiple steps (see #634984: Registration form breaks with add-more buttons). Let's make coding multistep forms as easy as coding usual forms! (for more thoughts on that see ajax #84).
Comment #31
chx CreditAttribution: chx commentedWell, OK. We wanted to make things easier but no magic is better I must admit.
Comment #32
Dries CreditAttribution: Dries commentedWe wanted to make things easier but no magic is better I must admit. I tried to parse that sentence but I can't really make sense of it -- probably because I'm less versed in English than you are. chx, are you suggesting this patch adds magic? If you have a concern, could you please articulate it? We were holding this patch up to get your opinion, so I'd like to make sure I understand it. Thanks!
Comment #33
sun- Reworked the $form_state documentation. (which are quite interesting, btw! Thanks, effulgentsia!)
- Removed unrelated changes.
This makes so much sense!
Comment #34
sun@Dries: No, this patch only removes ugly magic :)
Comment #35
Dries CreditAttribution: Dries commentedAh, I understand chx's comment now -- sorry. I agree that this is an improvement so committed to CVS HEAD.
Comment #36
yched CreditAttribution: yched commentedThe commit also contained all or parts of #601584: setUp() function for unit and web test cases should reset all resettable statics
Comment #37
sun@yched: I can only guess you posted to the wrong issue?
Also marking needs work for module upgrade documentation.
Comment #38
yched CreditAttribution: yched commentedsun: no no, correct issue. http://drupal.org/cvs?commit=292080 contains this patch + bits of #601584: setUp() function for unit and web test cases should reset all resettable statics
Anyway, fixed now, Dries committed the other missing bits of that other patch.
Comment #39
Anonymous (not verified) CreditAttribution: Anonymous commenteddon't know if its exactly the right fix, but at least modules can be installed again.
Comment #40
Anonymous (not verified) CreditAttribution: Anonymous commentedComment #41
sunThat's correct. And the latest patch would have failed, but was committed too early.
Comment #42
yched CreditAttribution: yched commentedCame to the same conclusion, and approx the same patch.
Comment #43
sunComment #44
webchickThis patch still needs work. I get 9 exceptions in the Module => Enable/Disable Modules test.
times 3.
Comment #45
Anonymous (not verified) CreditAttribution: Anonymous commentedupdated patch, passes all module tests.
Comment #46
webchickOk, committed #45 to HEAD. Yay for allowing us to enable modules without Drush. :P
Comment #47
sunThis should be the proper fix.
Comment #48
webchickCommitted #47 as well.
Comment #49
sun.
Comment #51
drunken monkeyI think this still needs some documentation (and the "Needs Documentation" tag agrees), as the Form API handbook explicitly states that setting
$form_state['storage']
will also set$form_state['rebuild']
toTRUE
. In my opinion, the Converting 6.x modules to 7.x should at least have a short line about this change(s).Even though the Form API documentation does mention that
$form_state['storage']
is no longer treated in a special way, this might as well imply that setting any other non-special key in$form_state
would also rebuild the form.Comment #52
marcingy CreditAttribution: marcingy commentedComment #53
catchDowngrading from critical.
Comment #54
jhodgdonSounds like this needs both Upgrade Guide documentation and a mention in the Forms API topic/group page on api.drupal.org
Comment #55
jhodgdonI did a search on d.o documentation, and the only page I found that looked at all relevant to forms with the words 'storage' and 'rebuild' on it was this one:
http://drupal.org/node/717746
It doesn't look like it implies that setting $form_state['storage'] automatically sets $form_state['rebuild'] to me, except right down at the bottom:
This page is marked as Drupal 6, but if someone who understands this issue could fix the last example or its comment (by adding in a note about Drupal 7), that would be good, and then mark the page as Drupal 6/7.
Meanwhile, I added this to the 6/7 module update guide, so I think the update doc tag is no longer needed.
http://drupal.org/update/modules/6/7#form-auto-rebuild