Problem/Motivation
When creating a custom entity, the status field can be not only a boolean type, as in node. This leads to the fact that when gin is enabled on the form for editing this entity, it looks bad.
Steps to reproduce
- Create a custom entity with a status field with a type other than boolean (for example, select)
- enable the gin edit form for the new entity
- go to the page for creating/editing an entity (see image)
Proposed resolution
configure the group only if it is a checkbox type, for example, a quick solution in GinContentFormHelper.php:
// Assign status to gin_actions if it input is checkbox.
$widget_type = $form['status']['widget']['#type'] ?? 'checkbox';
if ($widget_type === 'checkbox') {
$form['status']['#group'] = 'gin_actions';
}
Remaining tasks
- create a mr to solve the problem
- test with different types of status field (select, entity_reference, etc.)
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | custom-form-status-field-after.png | 130.83 KB | paul121 |
| #10 | custom-form-status-field-before.png | 135.65 KB | paul121 |
| #6 | status+3356717.png | 9.89 KB | maks oleksyuk |
| status.png | 15.49 KB | maks oleksyuk |
Issue fork gin-3440148
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 #4
pradhumanjain2311 commentedComment #5
saschaeggiCan you please test this with what we're working on in #3356717: Move Action buttons to sticky header?
Comment #6
maks oleksyuk commentedtested it on the dev version with the suggested changes from #3356717: Move Action buttons to sticky header
nothing has changed (I also noticed that the sidebar switch is hidden in the ellipsis, it seems it shouldn't be like that)
Comment #7
saschaeggi@maks
Okay thanks for verifying
That is intentional
Comment #10
paul121 commentedWe have experienced this same issue in farmOS for some time where the entity
statusfield is not a checkbox. I solved it in other ways (our own version of GinContentForm so to say) but agree with the proposed fix to only move the status when it is a checkbox.Furthermore, I'm running into this issue on *simple forms* (not entity forms, not gin content forms) after #3356717: Move Action buttons to sticky header. With this change any
statusfield in a form is moved out of the form to the actions area. Not only is this unexpected, but it also results in this status field not being included in the form submission (I believe because the status is moved without the additional template changes that content forms receive?)I think the fix is two parts:
1. Only move the status field on gin content forms
2. Only move the status field when it is a checkbox
I've opened a new MR with these changes. It also includes some changes to simplify GinContentFormHelper logic and also likely increase performance (don't invoke the
gin_content_form_routeshook multiple times!!!)Comment #11
paul121 commentedI've rebased this MR onto the latest 8.x-3.x, there was only one minor conflict with the last commit with this MR. Still need a review on this
Comment #12
maninders commentedNot able to Replicate this issue. With drupal version(11.0.x) and gin theme version(8.x-3.x-dev), Checked with installing examples module (https://www.drupal.org/project/examples) also, But not able to reproduce it. Let me know if other specific configuration is needed, thanks!
Comment #13
paul121 commentedHi @maninders, appreciate you trying to recreate this. The important thing is that the form you are testing has a form field called
status. I'm not sure if there is a custom form in the Examples module that fits this criteria. Testing likely requires creating a custom form.Comment #14
paul121 commentedI tested with the latest 8.x-3.x and confirmed the same issue is happening. There were some changes in GinContentForm so I've rebased my MR 446 onto the latest 8.x-3.x. Again, the full diff for this MR is a little ugly, please review the 4 commits individually to better understand the changes. I changed the order of these commits to make them easier to review.
The first two commits fix the issues previously described in this issue.
The third commit in the MR has the most changes because it combines two if statements into one and un-indents code from a nested if statement to simplify relevant logic in GinContentHelper::formAlter. These are the two if statements before changes:
In the last commit, instead of calling isContentForm() and invoking `hook_gin_content_for_routes` 3 separate times we can save the result in a variable and reference this value as needed.
Ultimately, the logic in the two above if statements are simplified to:
I mentioned in Slack that I might open a separate issue with these additional changes that are not necessary to fix the issue. But because these changes would either conflict with or be dependent on the fix in this MR, it is a much easier contribution to include them here. If maintainers still consider this out of scope then please only consider the first two commits from my MR. Cheers
Comment #15
jurgenhaasYes, agreed. While it is literally off-topic, it really makes sense to optimize this code altogether. I've looked through and I'm happy with it, so setting to RTBC.
@paul121 maybe we should also open a follow-up issue to optimize
\Drupal\gin\GinContentFormHelper::isContentFormas we should probably cache the result of that fairly expensive method.Comment #16
paul121 commentedOh interesting! I haven't done something like this before. Curious how you would go about that.
Comment #18
saschaeggiThanks Paul for your work on this 👏
Comment #19
flocondetoileHello,
Just updated Gin.
Looks like the value of
$widget_type = $form['status']['widget']['#type'] ?? FALSE;is alsways false in my case.Because the #type to check is in
$form['status']['widget']['value']['#type']and not in$form['status']['widget']['#type'].And so the status checkbox doesn't go into the gin sticky actions / status container.
Am I alone ?
Comment #20
jurgenhaas@flocondetoile you're correct. I missed that as I had content moderation turned on where we don't have that checkbox at all. I'll propose a fix in a minute.
Comment #22
jurgenhaasPlease give the new MR a try.
Comment #23
flocondetoileLooks good and fix the issue
Comment #26
saschaeggiComment #27
saschaeggiThanks @flocondetoile 👏