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.)

Issue fork gin-3440148

Command icon 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

Maks Oleksyuk created an issue. See original summary.

pradhumanjain2311 made their first commit to this issue’s fork.

pradhumanjain2311’s picture

Status: Active » Needs review
saschaeggi’s picture

Status: Needs review » Postponed (maintainer needs more info)
Related issues: +#3356717: Move Action buttons to sticky header

Can you please test this with what we're working on in #3356717: Move Action buttons to sticky header?

maks oleksyuk’s picture

Version: 8.x-3.0-rc10 » 8.x-3.x-dev
Status: Postponed (maintainer needs more info) » Needs work
StatusFileSize
new9.89 KB

tested 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)

saschaeggi’s picture

@maks

tested it on the dev version with the suggested changes from #3356717: Move Action buttons to sticky header
nothing has changed

Okay thanks for verifying

(I also noticed that the sidebar switch is hidden in the ellipsis, it seems it shouldn't be like that)

That is intentional

paul121 made their first commit to this issue’s fork.

paul121’s picture

Status: Needs work » Needs review
StatusFileSize
new135.65 KB
new130.83 KB

We have experienced this same issue in farmOS for some time where the entity status field 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 status field 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 thegin_content_form_routes hook multiple times!!!)

paul121’s picture

I'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

maninders’s picture

Not 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!

paul121’s picture

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!

Hi @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.

paul121’s picture

I 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:


    // Sticky action buttons.
    if ($this->stickyActionButtons($form, $form_state, $form_id) || $this->isContentForm($form, $form_state, $form_id)) {
      // Action buttons.
      if (isset($form['actions'])) {

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:

if (($use_sticky_action_buttons || $is_content_form) && isset($form['actions'])) {

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

jurgenhaas’s picture

Status: Needs review » Reviewed & tested by the community

Yes, 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::isContentForm as we should probably cache the result of that fairly expensive method.

paul121’s picture

maybe we should also open a follow-up issue to optimize \Drupal\gin\GinContentFormHelper::isContentForm as we should probably cache the result of that fairly expensive method.

Oh interesting! I haven't done something like this before. Curious how you would go about that.

saschaeggi changed the visibility of the branch 3440148-remove-hardcoding-group to hidden.

saschaeggi’s picture

Status: Reviewed & tested by the community » Fixed

Thanks Paul for your work on this 👏

flocondetoile’s picture

Hello,

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 ?

jurgenhaas’s picture

Status: Fixed » Needs work

@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.

jurgenhaas’s picture

Status: Needs work » Needs review

Please give the new MR a try.

flocondetoile’s picture

Status: Needs review » Reviewed & tested by the community

Looks good and fix the issue

saschaeggi’s picture

Status: Reviewed & tested by the community » Fixed
saschaeggi’s picture

Thanks @flocondetoile 👏

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.