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
- For an admin user with domain configuration handling active, visit a pure #config_target config form such as Regional settings (/admin/config/regional/settings).
- Submit it so that validation fails.
- 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
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 #3
mably commentedComment #4
mably commentedCorrected 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).
Comment #6
mably commented