Problem/Motivation
Custom entity forms are not detected and layout is not improved (and in some cases at least, form actions are hidden).
Steps to reproduce
Create a custom entity (drupal generate:entity:content with Drupal Console), and go to the creation / edition forms.
I attach an example of my custom EntityForm based on the generated one with elements grouped in adavanced / meta groups. It's the only changes in custom module providing custom content entity to make things work like node edit form.
Proposed resolution
- Match route patterns instead of route names in _gin_is_content_form().
- Ensure page attachments are OK (attach claro / gin libraries and theme functions)
- Ensure used templates are OK (add custom page suggestion)
- Ensure advanced group is in accordion mode (vertical tabs in other admin themes)
See attached patch.
Remaining tasks
It might be better to call an alter hook or something to decide when it's content form or not.
User interface changes
All entity creation / edition forms are handled the same as node forms.
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#22 | gin-improve-content-form-3188521-22.patch | 15.35 KB | jwilson3 |
| |||
#8 | interdiff-4-8.txt | 1.33 KB | hchonov |
#8 | 3188521-8.patch | 2.01 KB | hchonov |
| |||
#4 | 3188521-4.patch | 1.41 KB | hchonov |
| |||
gin--patch--content-form-detection-2.patch | 8.26 KB | rkcreation | |
Issue fork gin-3188521
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
chr.fritschWhat about adding a hook to
_gin_is_content_form()
so that other modules can opt-in to use the gin layouting?Comment #3
kevinquillen CreditAttribution: kevinquillen commented+1 for this. Just noticed this after generating two custom content entities with Drush.
Comment #4
hchonovI think as well that this is the way to go as it is a much cleaner and easier solution as there is not an universal pattern in which cases we would want to support the Gin Edit form layout.
Uploading a patch with that solution. I've added only a hook to collect routes, but we might also add one to alter the routes.
Comment #5
saschaeggiComment #6
volkerk CreditAttribution: volkerk at Thunder commentedI agree in it being beneficial for this to utilize a
hook_*_alter()
implementation to add the ability to remove routes as well.Comment #7
volkerk CreditAttribution: volkerk at Thunder commentedComment #8
hchonovAdding the alter hook.
Comment #11
paul121 CreditAttribution: paul121 commentedIn testing this out I found that pieces were needed from both the patch from #1 and the patch from #8 so I started a new issue fork that has both of these changes.
I added a final commit that enables the node content form for taxonomy terms. This is very simple and only for demonstration purposes! It adds some simple text and moves the
relations
fieldset to the sidebar. I've opened a MR to trigger the tugboat preview that demonstrates this: https://mr40-fdz2e5aj1kymtu7eronixscbhuy3knle.tugboat.qa/admin/structure...Overall, these changes are pretty simple and would make it much easier for other modules providing custom entity types to use the node edit form. The
hook_gin_content_form_routes
works great although I'm curious if this should be implemented as an event instead? This might be a bit more future-proof and allow for other options such as enabling the node edit form for all forms byid
orbase_id
(similar to existing logic already implemented in _gin_is_content_form()).It's also worth nothing that while this enables custom entity types to use the node edit form, this stillrequires that the
node
module is installed. We don't require thenode
module for farmOS, but are hoping to use the same layout of the node edit form. Regardless, this issue is a great first step towards supporting custom entity types!I'm not sure how possible it would be to decouple this from the node module... Gin is dependent on the
meta
form element which is provided by theNodeForm::form
method. The patch from #1 changes this because obviously custom entity types can't be expected to extend from theNodeForm
. But it also seems like Gin is providing most (but not all?) of the styling for thelayout-region-node-secondary
, and obviously is using the "node" in the name of these classes.. So maybe the CSS/JS (theclaro/node-form
library, and it's dependency onnode/form
are the only remaining implicit dependencies on the node module? Does it seem possible to abstract this out? If possible, this should probably be tackled in a separate issue.Comment #14
saschaeggiComment #15
volkerk CreditAttribution: volkerk at Thunder commentedMoved functionality to a "service" class.
Comment #16
chr.fritschLooks good. I think for terms we should create a separate issue.
Comment #17
saschaeggiI move this back to needs review as there were changes added :)
Comment #18
s.messaris CreditAttribution: s.messaris at Web Bunch commentedWhile all the work here is useful, I believe the theme should handle these forms out-of-the box, without needing opt-in.
Why not do something like this:
Comment #19
s.messaris CreditAttribution: s.messaris at Web Bunch commentedThe issue https://www.drupal.org/project/gin/issues/3231922 will need to be fixed for the edit form to work in some forms, adding as related.
Comment #20
trzcinski.t@gmail.com CreditAttribution: trzcinski.t@gmail.com commentedHey,
thanks a lot for the great work and a very cool theme :). I just came across this same issue and did some research before finding this issue.
I have looked at the patches and read the issue and have a few thoughts. First of all - I don't think it is good to use the node form template and it's classes. Styling for the `layout-region-node-secondary` sits in stable theme in node.module.css. Maybe we could just take them from there and use some more generic class name instead? Or even better (tho it might take some time till it gets accepted :D) - make a patch to stable theme with such generic classes (for example `layout-region-entity-secondary`).
This would require us to register a new theme hook - entity_edit_form and use it instead of the node one. This could be configurable via UI - we could exclude or include manually specific entity type (tho that's a nice to have I think ;)).
I also think we could adjust the `isContentForm` method a bit to allow for a better autodetection. Below just a quick sketch:
That's basically just a rough idea written quickly. I'll try to make a patch when I have a few moments if this approach makes sense.
Comment #21
jwilson3I've just figured out how to request push access and made the suggested change, as well as improved the examples.
Comment #22
jwilson3I also was unable to make a useful clean patch file from https://git.drupalcode.org/project/gin/-/merge_requests/40.patch
due to the GinContentform.php being renamed to GinContentFormHelper.php it somehow left a dirty file when applying the patch with composer, so here is a patch of work to-date based on the diff between the MR branch and 8.x-3.x branch after a rebase.
https://git.drupalcode.org/issue/gin-3188521/-/compare/8.x-3.x...3188521...
Edit. I later figured out that https://git.drupalcode.org/project/gin/-/merge_requests/40.diff produced a unified diff file, which is better than the patch file mentioned in Drupal docs, as it doesn't try to reapply intermediate commits in the MR, one on top of the other, like the patch file does.
Comment #24
PasqualleTested with the Box module. Form and color changes working nicely.
Comment #25
saschaeggiComment #26
saschaeggiComment #27
DieterHolvoet CreditAttribution: DieterHolvoet at Minsky commentedLooks good! The only real change I noticed is that the content_lock unlock button moved to the sidebar, but that's okay.
Comment #28
volkerk CreditAttribution: volkerk at Thunder commentedtested this by using the hooks to enable meta on 'entity.taxonomy_term.edit_form' and 'entity.taxonomy_term.add_form'.
We should add a follow-up to enable this on taxonomy terms by default (and move relations details into meta).
I think this is good to go.
Comment #30
saschaeggiThanks to everybody who participated in this!
Comment #32
meladawy CreditAttribution: meladawy as a volunteer commentedThese changes are merged to dev and beta1 released before reverting commit 90da47. Currently action buttons are not showing anymore in the taxonomy forms. I created a follow-up ticket on this https://www.drupal.org/project/gin/issues/3270626
Comment #33
saschaeggi@meladawy fyi: that was never part of Gin (yet) and was for testing purposes only. So it is correct how it was merged.
Comment #34
meladawy CreditAttribution: meladawy as a volunteer commented@saschaeggi so do you expect any websites using beta1 version to use the hooks to enable the actions on taxonomy forms?