Remove hardcoding #group for the status field

Created on 11 April 2024, 8 months ago
Updated 26 April 2024, 8 months ago

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

๐Ÿ“Œ Task
Status

Active

Version

3.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @maks oleksyuk
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia pradhumanjainOSL

    pradhumanjain2311 โ†’ made their first commit to this issueโ€™s fork.

  • Pipeline finished with Success
    8 months ago
    Total: 186s
    #157765
  • Status changed to Needs review 8 months ago
  • Status changed to Postponed: needs info 7 months ago
  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland saschaeggi Zurich

    Can you please test this with what we're working on in โœจ Move Action buttons to sticky header Fixed ?

  • Status changed to Needs work 6 months ago
  • tested it on the dev version with the suggested changes from โœจ Move Action buttons to sticky header Fixed
    nothing has changed (I also noticed that the sidebar switch is hidden in the ellipsis, it seems it shouldn't be like that)

  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland saschaeggi Zurich

    @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

  • First commit to issue fork.
  • Pipeline finished with Failed
    6 months ago
    Total: 272s
    #211250
  • Status changed to Needs review 6 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States paul121 Spokane, WA

    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 โœจ Move Action buttons to sticky header Fixed . With this change and 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!!!)

  • Pipeline finished with Success
    6 months ago
    Total: 218s
    #211260
  • Pipeline finished with Success
    3 months ago
    Total: 258s
    #286618
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States paul121 Spokane, WA

    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

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Maninders

    Not able to Replicate this issue on my local.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States paul121 Spokane, WA

    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.

  • Pipeline finished with Success
    2 days ago
    Total: 148s
    #370440
  • Pipeline finished with Success
    2 days ago
    #370446
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States paul121 Spokane, WA

    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

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany jurgenhaas Gottmadingen

    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.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States paul121 Spokane, WA

    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.

  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland saschaeggi Zurich

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

  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland saschaeggi Zurich

    Thanks Paul for your work on this ๐Ÿ‘

Production build 0.71.5 2024