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/Motivation
In several separate issues like #2318087: Replace $form_state['input'] with FormState::getUserInput(), we've been adding methods to FormState. With beta imminent, it seems like a better idea just to solidify the interface now, and convert things second.
Proposed resolution
Add getters and setters for all appropriate properties on FormState
Alter get/set/has to work only on custom properties, not internal ones.
Remove FormState::__construct() in favor of setFormState()
Use new methods in Drupal\Core\Form and Drupal\Tests\Core\Form to ensure they satisfy core's needs
Remaining tasks
N/A
User interface changes
API changes
Adding methods to FormStateInterface
Comment | File | Size | Author |
---|---|---|---|
#19 | interdiff.txt | 2.16 KB | tim.plunkett |
#19 | 2332389-form_state-19.patch | 121.42 KB | tim.plunkett |
#15 | interdiff.txt | 4.95 KB | tim.plunkett |
#15 | 2332389-form_state-15.patch | 120.91 KB | tim.plunkett |
#13 | interdiff.txt | 2.27 KB | tim.plunkett |
Comments
Comment #1
tim.plunkettComment #2
sunNice start :)
1. All Boolean setters should force-cast the passed value to (bool), IMO.
2. The class properties should use $lowerCamelCasing.
Type-hint array (interface change)
1.
disableCache()
orforceDisableCache()
?2. This method should not accept a value; the value is always TRUE and it cannot be reverted (because doing so would break the code that originally asked for it to be disabled).
Like 'no_cache', 'executed' is also immutable, once it is TRUE.
Boolean:
isValidationEnforced()
?Boolean:
isProcessingInput()
?Boolean:
isBypassingProgrammedAccessChecks()
?Comment #4
tim.plunkettWe can't use lowerCamelCasing until ArrayAccess is gone (without adding Yet Another Legacy layer), but I addressed the rest of your feedback, and fixed the fails.
Comment #6
tim.plunkettComment #7
tim.plunkettMore progress.
Only thing left is filling in the @todos, and making sure we're good with the naming.
Comment #8
tim.plunkettComment #9
tim.plunkettDid a review myself, and noticed I'd forgotten to add these to the interface.
Comment #10
dawehnersuggested to add isMethod('get') which allows you to ensure that 'GET' and 'get' works. @see Request Note: Here is also one space missing.
What is the reason why this worked before?
Is this a functional change? Just changing behavior here could be really fragile, for example for the views UI.
<3
Isn't rebuild a boolean, so isRebuild?
Did we considered to throw an exception instead if you don't pass in a boolean? Just curious.
...
Why is there no method for that? Can't you disable the redirection from outside?
80 chars
What actually happened with the 'foo][syntax'? Did we dropped them at some point?
I wonder why you have added those @see statements but just for some of them. Doesn't those bits of documentation makes more sense on the interface? Otherwise they would make more sense on the actual implementation, if this is an implementation detail.
Nitpick alarm: Not enough spaces
So there is a method, see above.
I don't see a point in differentiating NULL from [] here.
What happens with updating the args?
Mhh,, are we sure we don't introduce a regression here? display is not an object, it is just an array.
Doens't that change the behaviour? and why do you not use getBuildInfo?
Comment #11
tim.plunkett1) Fixed the space, but I'm not sure about changing the method. If it was named isMethod(), why would you assume it would compare to get/GET?
2) It used to work because getCacheableArray() took a parameter. But that was only used in this one place, and was weird.
3) It is not really a functional change, it just reflects reality. Previously, rebuildForm would ignore the $form_state['cache'] flag. Now it sets it. I ran this change past both @effulgentsia and @sun.
5) Fixed
6) I didn't consider it; @sun asked for the (bool) casts. I don't have a strong opinion.
7) :)
8) Fixed
9) Fixed
10) We still use that in some places, but this short array syntax is from #2316533: Add getValue/setValue/hasValue and isValueEmpty to FormState
11) I only added @see to the FormState properties when I felt the docs were best explained along with implementation details.
12) Fixed
14) Fixed
15) initializing the 'args' was something we had to do all over, but now FormState starts with them as an array by default, so this is not needed.
16) Really not sure what to do here.
17) No one needs that externally, I don't think its worth it.
18) I'm going to remove this change, and leave it for #2335659: Remove FormState ArrayAccess usage from core
Comment #13
tim.plunkettFixing the newly added PathElementFormTest
Comment #14
dawehner1) what about isMethodType maybe?
2) Okay cool
3) As long views preview, UI and exposed forms still works fine, cool!
6) Yeah just was throwing out some ideas from time to time
15) Lovely!
16) Mh, so can't we somehow get a reference here, maybe a set alternative with a reference?
Comment #15
tim.plunkett1) Works for me. Added a test.
16) This should work.
Comment #16
dawehnerCool, IS?
Comment #17
tim.plunkettClarified with @dawehner that he meant a change record.
I think that https://www.drupal.org/node/2310411 should be expanded to cover this scope when it is committed, and a new final CR could be published after #2335659: Remove FormState ArrayAccess usage from core goes in...
Comment #18
jibranMore then 80 chars.
Comment #19
tim.plunkettThanks.
Comment #20
jibranThank you @tim.plunkett for fixing those issue. This is RTBC IMO.
Comment #21
alexpottLet's get them CRs updated :)
Committed ee6ddbe and pushed to 8.0.x. Thanks!
Comment #23
tim.plunkettThanks! Working on the CR now.
Found this minor issue, sorry about that: #2336405: Follow-up: FormStateInterface::getGroups() should return by reference