Problem/Motivation
Hidden fields are completely removed from the form object making form alters unnecessarily difficult.
Proposed resolution
Add field to form but set #access to false
Remaining tasks
- Add tests
- Review
- Commit
User interface changes
None
API changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 1-4-interdiff.txt | 4.62 KB | alexpott |
| #4 | 2378947.4.patch | 6.03 KB | alexpott |
| #1 | 2378947.1.patch | 1.41 KB | alexpott |
Comments
Comment #1
alexpottComment #2
alexpottI discovered this issue whilst reviewing #2275463: Path field does not respect settings in form display
Comment #4
alexpottWell that exposes some interesting things...
We need default_widgets for the timestamp fields, BooleanCheckboxWidget incorrectly sets default values to booleans :), and Quickedit wasn't really testing is a revision log value was set.
Comment #5
amateescu commented@alexpott, we specifically didn't use #access => FALSE in the 'hidden' widget patch (#1465774: Provide a 'Hidden' field widget) in order to prevent bugs like this #1205822: File(s) silently deleted when #access=false.
I'm wondering what does that mean exactly.
Comment #6
yched commentedThe patch includes hidden fields in the form by using an arbitrary widget (the default_widget for the field type) and setting #access FALSE.
Not too fond of the idea. If the widget is changeable / hideable to begin with, it means form_alters can't rely on the structure of a specific widget anyway - you can only assume $form[$field_name]['widget'] at best, not what's inside. So why should we bother putting anything in there (default widget or anything else) ?
Comment #7
yched commentedThe big idea behind EntityFormDisplay is that it's the object that is passed through all the form build callstack to let code build the form according to what has been configured.
I'd say form_alters need to do the same (the EFD is in $form_state), and do their stuff based on how the form is configured; It feels weird to pretend the form contains stuff that aren't there to work around that ? (which, as explained in #6, you can only do to a very limited extend anyway)
Comment #8
yched commentedAlso note that hook_form_widget_alter() lets you alter what's *inside* a widget, and solves the question of "is the widget actually present or not ?" (the hook is not fired if the field is hidden in the form).
So form-level form_alters are only needed for cross-field alters, which mitigates the issue described here ?
Comment #9
berdirYes, I'm worried about this as well/don't really see why we need it.
Fun example: Let's say you have an entity reference to nodes and you have one million nodes. The default widget for entity reference is a select AFAIK. So if you hide it, it would render it like that, load 1million nodes (or try to), put them in a select, and then not show it.
Right, that is a great idea :p
Comment #10
amateescu commentedSomeone must have lied to you, it's entity_reference_autocomplete :)
I still don't really get what's issue described here by that one sentence from the IS...
Comment #11
alexpottWell elsewhere we've been removing conditionals from form arrays so that form_alters don't need a mass of conditionals. This issue was created as a result of reviewing https://www.drupal.org/node/2275463. Perhaps this is mostly about base fields going missing? If you look at path_entity_base_field_info ()and then path_form_node_form_alter() - it seems super odd that the form alter should not be able to rely on path actually being there.
Comment #12
fagoWell, problem is that the $form array will look different based on the used widget and widget settings anyway, so we cannot remove the burden of the form alter to respect possibly different form structures per form mode and/or its display configuration. It's not only about being there / not there :/
Comment #13
alexpottLet's close this issue as works as designed for now.