Problem/Motivation

When you click "Add field group" while managing a non-default form mode or view mode, the new group is not created on the mode you are editing. It is silently created on the default mode instead.

This is a regression introduced by the coding standards cleanup in #3490746: Fix ESLint, phpcs, phpstan, cspell coding standards (commit 9dd5c102, 2026-06-11), so it affects 4.x-dev from that date on.

Steps to reproduce

  1. Install field_group 4.x-dev (commit 9dd5c102 or later).
  2. Add a second form mode to a content type and enable it under "Custom display settings".
  3. Go to "Manage form display" for that new form mode and click "Add field group".
  4. Create a group of any type.
  5. Result: the current form mode does not have the new group. It was created on the default form mode. The same happens with view modes on "Manage display".

Proposed resolution

The cause is a one-line mistake in the #3490746: Fix ESLint, phpcs, phpstan, cspell coding standards cleanup. FieldGroupAddForm::buildForm() used $this->getRequest()->get('form_mode_name') to read the mode. Because phpstan discourages Request::get(), it was replaced like this:

-      $this->mode = $this->getRequest()->get('form_mode_name');
+      $this->mode = $this->getRequest()->request->get('form_mode_name');

That replacement looks in the wrong place. form_mode_name and view_mode_name are route parameters, and route parameters live in $request->attributes. The $request->request bag only holds POST body fields, so the lookup now always returns NULL and the code falls back to 'default'.

The fix is to read from the attributes bag, which is what the old Request::get() call was finding all along:

-      $this->mode = $this->getRequest()->request->get('form_mode_name');
+      $this->mode = $this->getRequest()->attributes->get('form_mode_name');

and the same for view_mode_name two lines below.

The attached patch contains the two-line fix plus a regression test, ManageDisplayTest::testCreateGroupOnNonDefaultMode(). The test creates a custom form mode and a custom view mode, adds a group through the UI on each, and asserts the group ends up on that mode and not on default. It fails on current 4.x HEAD and passes with the fix.

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

loze created an issue. See original summary.

loze’s picture

Issue summary: View changes

loze’s picture

Status: Active » Needs review
csakiistvan’s picture

Assigned: Unassigned » csakiistvan
csakiistvan’s picture

Assigned: csakiistvan » Unassigned
Status: Needs review » Reviewed & tested by the community

Environment

  • Drupal: 11.4.1
  • PHP: 8.5.5
  • Database: MariaDB 10.11.16
  • DDEV: v1.25.2
  • Field Group: 4.0.0 (affected code identical in 4.1.0-alpha2)
  • Browser: Chrome

Prerequisites

  • The Field Group module enabled.
  • This is a library dependency declaration issue, not a visible runtime failure: core/once is normally already loaded by another core library, so the missing declaration only surfaces a ReferenceError: once is not defined in edge cases with minimal library loading. It is verified by inspecting the resolved library dependencies rather than through the browser.

Steps

  1. Apply the fix from MR !135: add core/once to the dependencies of the details_validation, tab_validation, and tabs_validation libraries in field_group.libraries.yml.
  2. Rebuild caches: ddev drush cr
  3. Inspect the resolved dependencies of the three libraries:

    ddev drush php-eval 'foreach (["details_validation","tab_validation","tabs_validation"] as $n) { $l = \Drupal::service("library.discovery")->getLibraryByName("field_group", $n); print $n . ": " . implode(", ", $l["dependencies"]) . "\n"; }'

Expected results

  • Each of the three validation libraries lists both core/jquery and core/once as dependencies.
  • The once function used in the corresponding JavaScript files is guaranteed to be available.

Actual results

Before the fix, the details_validation, tab_validation, and tabs_validation libraries declared only core/jquery, even though their JavaScript files receive once as a parameter and call it directly, leaving the core/once dependency undeclared. After the fix, all three libraries resolve with core/jquery and core/once, so the once function is always loaded before the scripts run.


Testing produced with the assistance of an LLM.

anybody’s picture

Thank you all! Merging!

  • anybody committed 2cc66541 on 4.x authored by loze
    Resolve #3614498 "Add field_group view mode regression"
    
anybody’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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