Found while building the domain_config_switcher submodule for Domain Extras (#3592820).

Problem

DomainConfigUiFormHooks::toggleButton() adds the enable/disable control to domain-enabled configuration forms as a render element of #type link (form key domain_config_ui_toggler). A link element has no #parents.

When such a form fails validation, core's form error walker (FormErrorHandler::setElementErrorsFromFormState() calling FormState::getError()) iterates foreach ($element['#parents'] as ...) over every element. For the toggler this emits:

Warning: Undefined array key "#parents" in Drupal\Core\Form\FormState->getError()

Under a strict error handler (BrowserTestBase, or sites that escalate warnings to exceptions) this becomes a hard failure and can mask the real validation error the user should see.

When it happens (corrected)

This only affects forms where the toggler is attached through the #after_build path: ConfigFormBase forms whose getEditableConfigNames() returns an empty array, i.e. the modern pure #config_target pattern using RedundantEditableConfigNamesTrait. For those, domain_config_ui adds the toggler in an #after_build callback, after the form builder has already assigned #parents to the tree, so the toggler never receives one.

Forms that override getEditableConfigNames() with real names (for example Basic site settings / system.site) take the direct path: the toggler is added during hook_form_alter and the form builder assigns its #parents, so they are NOT affected. The original system.site repro in this issue was therefore incorrect.

The bug is reachable in current core through forms using RedundantEditableConfigNamesTrait, for example Regional settings (/admin/config/regional/settings), Logging (/admin/config/development/logging), File system, JSON:API, and the Views settings form.

Steps to reproduce

  1. For an admin user with domain configuration handling active, visit a pure #config_target config form such as Regional settings (/admin/config/regional/settings).
  2. Submit it so that validation fails.
  3. Observe the "Undefined array key #parents" warning emitted during the form rebuild.

Fix

Give the toggler an explicit empty #parents so the error walker resolves no error for it instead of reading an undefined key. See the MR, which also adds a regression test on the #after_build path (a fixture form using RedundantEditableConfigNamesTrait): it fails on the warning without the fix and passes with it.

Issue fork domain-3592825

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

mably created an issue. See original summary.

mably’s picture

Status: Active » Needs review
mably’s picture

Issue summary: View changes

Corrected the summary. The original system.site repro was wrong: SiteInformationForm overrides getEditableConfigNames() so it takes the direct path and the form builder assigns the toggler its #parents. The bug is specific to the #after_build path used for pure #config_target forms (empty getEditableConfigNames(), via RedundantEditableConfigNamesTrait), reachable in current core via Regional settings, Logging, File system, JSON:API and the Views settings form. Pushed an MR with the #parents fix plus a regression test on that path (fails on the warning without the fix, passes with it).

  • mably committed 15468931 on 3.x
    fix: #3592825 domain_config_ui: toggler link element has no #parents,...
mably’s picture

Status: Needs review » 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.