Drupal 10.2+ config forms that use the new #config_target are not detected by Config Enforce

Created on 7 June 2024, 11 months ago
Updated 9 June 2024, 11 months ago

Problem/Motivation

After doing a bit of a deep dive into what's causing unexpected test failures on Drupal 10.2 in 🐛 Cannot access Block, Field UI, Views UI config pages when Config Enforce Devel is enabled Needs review (we use the system logging form for one of our tests), it looks like the new, opt-in #config_target form element property introduced in #config_target in ConfigFormBase: using validation constraints for editing simple config is the reason. This doesn't prevent enforcing a config, but does cause Config Enforce (and Config Enforce Devel) to not associate a given config form that uses #config_target with a configuration, so our embedded enforce form never shows up on that form. Such forms are not required to list their config in getEditableConfigNames() which why our detection is now failing, as we rely on that method to give us the simple config names; see 📌 Do not require the config in #config_target to be listed in getEditableConfigNames() Active .

Steps to reproduce

Visit any of these core forms in Drupal 10.2.x and observe that the Config Enforce embedded enforce form never shows up for these:

How did I come up with this list? I looked at all the forms that use the new \Drupal\Core\Form\RedundantEditableConfigNamesTrait, which is a small number in core right now but will grow over time and likely be applied to all the forms in core that previously returned a non-empty array from getEditableConfigNames(); see https://git.drupalcode.org/project/drupal/-/merge_requests/5236/diffs

Proposed resolution

We need to add support for #config_target but re-implementing core behaviour would be dumb and thankfully core provides a new non-@internal \Drupal\Core\Form\ConfigTarget value object that has a fromForm() static method we can use.

We'll want to figure out how to handle Drupal core older than 10.2.x; we can probably just create a backwards compatible class_alias for \Drupal\Core\Form\ConfigTarget if it doesn't exist with dummy methods that return empty values?

Remaining tasks

TBD; see previous heading.

User interface changes

Config Enforce stuff shows up once again on the above forms so you can enforce from the form again.

API changes

Minimal or none? I suppose a backwards compatible wrapper might be an additional API addition which is technically a change in the broad sense but shouldn't change existing stuff.

Data model changes

Probably none.

Feature request
Status

Active

Version

1.0

Component

User interface

Created by

🇨🇦Canada ambient.impact Toronto

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

Comments & Activities

Production build 0.71.5 2024