Allow subforms to have the context of the parent form state as-well.
| Comment | File | Size | Author |
|---|---|---|---|
| pass-parent-form-state.patch | 653 bytes | amitaibu |
Allow subforms to have the context of the parent form state as-well.
| Comment | File | Size | Author |
|---|---|---|---|
| pass-parent-form-state.patch | 653 bytes | amitaibu |
Comments
Comment #1
casey commentedNot sure yet. When having multiple subforms, memory usage could become massive. Also subforms depending on parent's state will be minimal I reckon.
Maybe we should only pass parent's build id so if a subform needs parent state it can load it from cache.
Comment #2
amitaibu> Maybe we should only pass parent's build id so if a subform needs parent state it can load it from cache.
Yes, sounds better
Comment #3
amitaibuI think that actually passing the form-build-id isn't enough, as it will be created only after form submit.
I wanted to add something like this in subform_element_process()
however, it seems not to pass.
The idea is that for example the wrapper form can pass $form_state['subform_cascase']['foo'] = 'bar'.
In turn, modules that for example implement hook_form_alter() can check those values, to get more context about the wrapping form.
Comment #4
casey commentedRight, but there would be an issue with ajax functionality in subforms.
If the subform contains an ajax button and that button is pressed, only the subform is processed. No subform_element_*() functions are called. So you won't have access to $form_state['temporary']['subform_element_parents_cascade'] in your subform. And I don't really like adding the parent state as a non-temporary; memory usage.
But parent's build_id is always accessible. So I added $subform_state['subform_parent']['form_id'] and $subform_state['subform_parent']['build_id']. And a new API function subform_get_parent_state($subform_state).
Comment #5
casey commentedAlso, you can already pass variables to a subform's state:
Plus some still undocumented feature, you can override any #{property} from subform's form element. For example:
Comment #6
amitaibuGreat addition!
maybe we should add a helper function to get the top most parent? (user-modal is currently doing it)
Comment #7
amitaibubtw, user-modal is now using the overlay to get the modal, instead of CTools' modal, and I've added a well-documented user-modal-example -- I think it can help devs better understanding how to use subforms.