Problem/Motivation
The field_attach_form hooks were removed in #2095195: Remove deprecated field_attach_form_*(), but by removing this, it also removed the possibility to alter entity forms.
An example:
There is currently an issue in field_group when paragraphs are added on the node form. #2637148: Field Group not working on node edit inside paragraph
What is happening: Because of the lack of hooks, field_groups tried to add the grouping via a regular form_alter. This works perfect for node forms, but is causing issues when multiple entity forms are embed into 1 form (paragraphs, inline entity form, field_collection, ...). Field_group has no clue that multiple entity forms will be shown, and on what places this will be. (unless we loop recursive trough the whole form, but even then we probably have missing info).
Proposed resolution
Introduce an alter hook in EntityFormDisplay:buildForm. This will provide other modules the option to hook into the building of an entity form. Even when multiple entity forms are build into 1 form.
User interface changes
None
API changes
A new hook is introduced
Comment | File | Size | Author |
---|---|---|---|
#27 | 2640056-26.patch | 1.68 KB | pcambra |
#12 | screencapture-m0g9y-ply-st-node-1-1457172709854.png | 440.59 KB | Revathi Manohar |
#2 | 2640056-2.patch | 682 bytes | nils.destoop |
Comments
Comment #2
nils.destoop CreditAttribution: nils.destoop as a volunteer and at Wunder commentedAn example patch, but probably a better name should be found.
But i tested the hook with field_group, and all issues are gone then. I can add group info for my node, and for my paragraph. The form is rendered correctly.
Comment #3
nils.destoop CreditAttribution: nils.destoop as a volunteer and at Wunder commentedComment #4
swentel CreditAttribution: swentel as a volunteer commentedHmm, interesting. EntityViewDisplay has an calling entity_display_build (looking at it, I even wonder if that hook actually works since $key seems totally wrong there, but that's for another issue) - maybe it could be something like entity_form_display_build then ?
Another option maybe: what if move this alter call into EntityFormBuilder::getForm, in analogy with EntityViewBuilder and name it something like 'entity_form'
e.g.
Definitely needs tests and an entry in entity.api.php
Comment #5
nils.destoop CreditAttribution: nils.destoop as a volunteer and at Wunder commentedMoving it to getForm will probably lead to the same issue like we have now.
This is how paragraphs is embedding the entity form: http://cgit.drupalcode.org/paragraphs/tree/src/Plugin/Field/FieldWidget/...
Comment #6
swentel CreditAttribution: swentel as a volunteer commentedHa, interesting .. form in a form, always tricky stuff :)
Been looking at how Entity Inline Form deals with this and they are calling an alter themselves on the embedded form (see EntityInlineForm::entityForm()). Maybe in the end, that's the that's a better idea for paragraphs module as well ?
(I'm even wondering whether they shouldn't start depending on IEF, less code to maintain as well, but that's separate issue for them)
Comment #7
Petr IllekHi,
it is safe to use the patch from #2 at this moment as temporary solution?
Or it is better to wait for some real solution?
Thanks a lot for your work so far.
Comment #8
geoffreyr CreditAttribution: geoffreyr commentedWould this be the reason why it's currently impossible to use Field Groups to modify the form layout of Contact Forms?
Comment #9
swentel CreditAttribution: swentel as a volunteer commented@Petr Illek no, don't use this patch for now. I don't know how @zuuperman tackled it in the end, but we talked in IRC and we were close to setting this to won't fix.
Comment #11
Revathi Manohar CreditAttribution: Revathi Manohar as a volunteer and commentedhi,
i am also tested with the field group and paragraph demo modules. image + text are grouped.
thank you
Comment #12
Revathi Manohar CreditAttribution: Revathi Manohar as a volunteer and commentedhi,
i am also tested with the field group and the paragraph modules.image and paragraph are grouped and working fine,if it have any further issue kindly post.according to patch it is working fine.
Comment #13
reekris CreditAttribution: reekris commented@revathi seems like you are posting about another issue? This issue is about getting field groups to work when editing content and your screenshot is showing a viewed node. I'm setting this back to previous status since I don't believe it is actually fixed.
Comment #14
swentel CreditAttribution: swentel as a volunteer commentedanother at #2691723: Add a hook to alter entity form displays
Comment #15
swentel CreditAttribution: swentel as a volunteer commentedClosed #2691723: Add a hook to alter entity form displays - moving to needs work for tests.
Comment #16
jwilson3Copying Comment #4 from dawenher here from the other issue that explains what tests are required:
Comment #20
artis CreditAttribution: artis at Texas Creative commentedThis has been fixed elsewhere it seems. Feel free to re-open if I'm wrong.
Comment #22
nedjo@artis
Anything you can point or link to that makes it seem like this is fixed? Thanks.
Comment #23
plachThis doesn't seem to be fixed at all_ there is still no hook allowing to alter the form display building process AFAICT.
Comment #24
geek-merlinAnother one rides the bus! This bites in that related issue.
Comment #25
geek-merlinSo let's sort it out:
* we have a patch in that dup issue #2691723-2: Add a hook to alter entity form displays that adds a simple hook but needs work for tests
* EDIT: also that patch needs doc (.api.php) for the introduced hook_entity_form_build
Note: I'm not sure if the hook is enough as sometimes modules need to know if they're in the top level entity form or an embedded entity form. But i'd leave this for a followup if needed.
Comment #27
pcambraRerolled and added the api docs, tests still missing. Worth mentioning that I think most of the use cases related to this could maybe solved by hook_field_access or a good old hook_form_alter.
Comment #34
longwaveThis issue came up in #bugsmash triage.
Myself, @lendude and @larowlan discussed it and agreed that it is not a bug and would be better classified as a feature request. The discussion above indicates that paragraphs and field_group have already worked around this, and there has been little recent interest in fixing this issue. Setting to "maintainer needs more info", if there is no further movement for this feature request in the future then it is likely to be closed as won't fix.
Comment #37
smustgrave CreditAttribution: smustgrave at Mobomo commentedPer #34, since it's been a year without movement going to go ahead and close.
If anyone disagrees please reopen expressing why though.
Thanks!
Comment #38
Liam MorlandThe code still contains this comment in two places:
If this won't be fixed, perhaps this comment should be removed.