Problem/Motivation
The FormBuilder class is complex and long, but large portions of it are not actually for building and processing, but for submissions.
This makes it harder to unit test, harder to understand the code flow, and harder to maintain.
Proposed resolution
Move form submission into a new class.
In order to minimize the changes for existing module code, have FormBuilder pass through those method calls to the new class.
Remaining tasks
N/A
User interface changes
N/A
API changes
No API break, but https://drupal.org/node/2121003 should be updated to clarify which service/interface executeSubmitHandlers() and redirectForm() are on now
Comments
Comment #1
tim.plunkettBuilding on the other patch, this is just to get something up.
Comment #4
tim.plunkettComment #5
sunAwesome! That's exactly the parity I thought of :-)
For consistency, I think the service ID should be form_submitter and the class name should be
FormSubmitter.Alternatively, we might want to go back to the other issue and quickly rename the validator into validation prior to commit?
Minor: The order of methods looks a bit off/reversed in the class and interface...
1. submitForm
2. executeSubmitHandlers
3. redirectForm
The validator interface calls the corresponding method
validateForm()— any particular reason for not renaming thissubmitForm()?Comment #6
tim.plunkett1) eeek I guess maybe we should.
2) Yeah this is very rough, I'll be rearranging the methods in both interface and class before I'm done, this is still WIP
3) So I did not yet move in FormBuilder::submitForm(). the validateForm() method takes a form and triggers validation. This handleFormSubmission() method cannot really be called to submit a form, it is used during form processing...
Comment #7
sunI'm not convinced that
FormBuilder::submitForm()belongs to this class. It lives/operates at the opposite end; i.e., it's an initial entry point to build a form + futz with$form_statein a way to auto-submit it, but doesn't interfere with the actual form submission logic.In turn, IMO this patch already covers pretty much everything the class should cover. Just some polishing and I'd consider it done :-)
Comment #8
tim.plunkettA lot moved around and the interdiff was useless.
#2209977: Move form validation logic out of FormBuilder into a new class went in!
Comment #9
sunApologies, I don't know how, but somehow I completely missed the following moved methods in the earlier patch:
These methods are not part of the form submission/processing logic at all.
They belong to the user input processing, which is (currently) performed during form building. Their abstract meaning is:
A positive result of that user input processing is stored in
$form_state- as if the user input had contained the actually required values to trigger that state natively (even though it did not).This information must be set and is consumed before the form validation + submission workflow begins. The effective triggering element can have additional form validation handlers assigned to it.
That is why it is not part of the submission workflow.
Comment #11
tim.plunkettGood point about the validation here. Pulled that part out.
Comment #12
sunThanks. Last remaining step from my perspective is: Naming.
Can we rename
FormSubmissionProcessorinto just simplyFormSubmitter, please?(ibid on the service ID:
form_submission_processor→form_submitter)FormSubmissionProcessoris completely out of line compared to everything else, which defeats the whole point of splitting up the main Form API concepts.FormProcessorcannot be used as name, because major parts of the actual form processing logic still live inFormBuilder::processForm()(which is fine). TheFormValidatorisn't aFormValidationProcessoreither. Despite the offer in #5, you objected to renameFormValidator. This is about the submission workflow of a form only; hence,FormSubmitter.Second, you wanted to re-order the methods in the class + interface to follow #5.2.
Comment #13
sunComment #14
tim.plunkettI think we need a second opinion on the class naming, resetting to needs review for that.
I reordered the methods, but I have execute and redirect swapped. I can fix that after we settle on a name.
Comment #15
pwolanin commentedFormSubmitter in analogy to FormValidator makes sense to me. Also, it's much shorter without really being less informative.
Comment #16
sunThanks for your prompt feedback, @pwolanin.
@tim.plunkett: Also, if you'd explain the underlying reasoning for naming it
FormSubmissionProcessor, then others might be able to relate to that (whichever) idea. Right now, I'm not able to see any reasoning that would make sense of that naming, so I assume you're interpreting it as "bikeshed" whereas I'm clearly not — the parity ofFormBuilder+FormValidator+FormSubmittercovers the main 3 Form API concepts in distinct classes whose names are fully in line.Comment #17
tim.plunkettNo, honestly now that we've moved the other "processing" code back out, I'm much less attached to it.
I pinged @pwolanin and @larowlan, we talked about it. @pwolanin commented above, and @larowlan pointed out that each name is clear and explanatory, but not any more than the other.
Renamed, and swapped the order of the methods to match #5.2
Comment #19
tim.plunkettDuh, bad copy/paste in form.inc
Comment #20
sunhandleFormSubmission()diverges fromFormValidator::validateForm(). Sadly we cannot usesubmitForm(), becauseFormBuilder::submitForm()already exists. Therefore:handleFormSubmission()todoSubmitForm().FormBuilder::doSubmitForm()is called directly.In light of that, I think we should create a follow-up issue to remove the additional interfaces from
FormBuilder, but I'm happy to move forward with this for now.That was my only remaining remark, so if we're fine with that, then I think this is RTBC.
Comment #21
tim.plunkettI'm fine with this.
It would have been just as easy for you to leave a review and let me update it, it would have helped me keep my branches clean, and then you could have cleanly RTBC'd it...
Comment #22
sunI only renamed that method name, so I'm comfortable to RTBC this patch. Thanks!
Comment #23
jibranI think @deprecated can be added here.
Comment #24
tim.plunkett#23, The same thing was done in the validate patch, we have all of the form.inc deprecated stuff to clean up first.
Comment #25
almaudoh commentedComment #26
catch20: form.submitter.20.patch queued for re-testing.
Comment #28
Jalandhar commentedHere is the Rerolled patch.
Comment #29
Jalandhar commentedBack to RTBC.
Comment #30
catchCommitted/pushed to 8.x, thanks!
Comment #32
tim.plunkettThanks @Jalandhar for rerolling!