Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem
- Many form submission handlers are manually calling into form_state_values_clean() today.
Goal
- Simplify form handling.
Proposed solution
- Make Form API call form_state_values_clean() before executing form submit handlers.
Comment | File | Size | Author |
---|---|---|---|
#15 | form-1729882-15.patch | 9.14 KB | tim.plunkett |
#10 | drupal8.form-state-values-clean.10.patch | 25.19 KB | sun |
#8 | drupal8.form-state-values-clean.8.patch | 25.25 KB | sun |
#6 | drupal8.form-state-values-clean.6.patch | 22.07 KB | sun |
#4 | drupal8.form-state-values-clean.4.patch | 17.79 KB | sun |
Comments
Comment #1
sunLet's see what breaks.
I know for sure that Taxonomy has at least 1-2 stone-age submit handlers that are still checking for 'op' instead of using dedicated #submit handlers.
Comment #3
sunAlmost all of the test failures are expected — "Undefined index: op" — those can be fixed very easily.
There's one nasty surprise though: The Views "wizard" multistep form implementation seems to depend on 'op', too... that might take more time to refactor :-/
Comment #4
sunAttached patch fixes most of the test failures.
Comment #6
sunAttached patch should resolve the Views UI failures.
Apparently, the Views Wizard plugin already contained a @todo about some weird validation logic in there. Resolved that while being there.
Comment #8
sunFixed Form\ProgrammaticTest.
Comment #10
sunComment #11
dawehnerWhat is the reason why catch DataBaseExceptionWrapper here? The usages i could found didn't used it.
So we don't want to have a redirect anymore? Not sure whether return actually works but there is at least an intention to do so.
Is there a fundamental reason we have to change so much in this patch? Couldn't we just replace $op with using triggered element?
Also lost?
Oh i thought the standard now suggests to prepend the "\"
Yeah I totally think we can remove that now, as it's silly complicated stuff.
Comment #12
sunThanks for reviewing!
re: Catching a database exception for
menu_get_item()
indrupal_retrieve_form()
:This allows DrupalUnitTestBase to submit forms programmatically without having to install the {menu_router} & Co database schemata first.
The include file from the route definition is optional, and that was only added to support processing of cached forms, which may be re-retrieved on a different router path (e.g., /system/ajax).
re: Redirects in form submission handlers:
All of these filter forms actually do not want to redirect anywhere. They want to show the form on the same page they were displayed before.
And yeah, the instances that returned a path as string from the submit handler did not redirect anymore in the first place. That way no longer works since D6, I think.
re: Different button submit handlers:
I think we're generally moving towards separate button submit handlers. But as you probably noticed, I only figured out later when doing the patch that I could as well just replace $form_state['values']['op'] with $form_state['triggering_element']['#value']...
Don't have a strong preference there myself. Not sure whether it's worth to revert the button submit handler changes (and redo them in a separate issue).
Comment #13
sun#10: drupal8.form-state-values-clean.10.patch queued for re-testing.
Comment #15
tim.plunkettReviving this.