Allow admin users to be reminded when forms in /admin are likely to alter configuration

Created on 12 May 2025, 2 days ago

Problem/Motivation

For some time, actually since at least Dev Days in Milan, I’ve struggled with how difficult it is for an administrator to be aware if a change on a production site might actually be changing the running configuration and, therefore, be liable for overwriting in a future code/config deployment.

I propose that, rather than a wholesale change of the /admin menu at this time, we optionally add an alert box to forms using a process inspired by the Configuration Override Warn module, using reflection to look for the method “getEditableConfigNames” and know it is editing config.

An admin user looking at a typical config form would see:

And there would be a toggle to enable the behaviour in /admin/

Steps to reproduce

n/a

Proposed resolution

new feature in core

Remaining tasks

Create proof of concept
Agree wording and placement of message and config option to enable

User interface changes

Added warning to all forms that alter configuration

Introduced terminology

API changes

Data model changes

Release notes snippet

Feature request
Status

Active

Version

11.1 🔥

Component

configuration system

Created by

🇬🇧United Kingdom rachel_norfolk UK

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

Comments & Activities

  • Issue created by @rachel_norfolk
  • 🇬🇧United Kingdom rachel_norfolk UK

    Adding link to Config Override Warn as inspiration

  • 🇬🇧United Kingdom rachel_norfolk UK

    Adding an option for the warning to include a custom message.

  • 🇬🇧United Kingdom rachel_norfolk UK

    Playing around with this a little and the following working “pseudo code” (i.e. please don’t actually use this as is - it is just to test ideas) gives the idea of what I’m thinking:

    function xx_form_alter(&$form, FormStateInterface $form_state, $form_id) :void {
    
      // Get out of here if it is not an admin form.
      if (!\Drupal::service('router.admin_context')->isAdminRoute()) {
        return;
      }
    
      // We need an actual object rather than just a jumble of array items.
      $form_object = $form_state->getFormObject();
    
      // Assume forms have no config to begin with.
      $has_config = FALSE;
    
      // Does the getEditableConfigNames method exist on the form?
      if (method_exists($form_object, 'getEditableConfigNames')) {
        $has_config = TRUE;
      }
    
      // Are we editing an entity that has config form for it's setup?
      if ($form_object instanceof EntityForm) {
        $entity = $form_object->getEntity();
        if ($entity instanceof ConfigEntityInterface && !$entity->isNew()) {
          $has_config = TRUE;
        }
      }
    
      // Permisions being permissions.
      if ($form_object instanceof UserPermissionsForm) {
        $has_config = TRUE;
      }
    
      // Blocks being blocks.
      if ($form_object instanceof BlockListBuilder) {
        $has_config = TRUE;
      }
      // Okay, warn people.
      if ($has_config) {
        \Drupal::service('messenger')->addWarning(t("This form is likely to alter the running configuration of the site and, therefore, changes should probably go through the development quality processes."));
      }
    
    }
    
  • 🇬🇧United Kingdom rachel_norfolk UK

    Note: BlockListBuilder extends ConfigEntityListBuilder and that ’s probably worth looking out for, rather than the special case of blocks.

  • 🇧🇪Belgium swentel

    Actually, reading again, it's not the same, sorry!

Production build 0.71.5 2024