- 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
Isn't this the same as 🐛 Display status message on configuration forms when there are overridden values Fixed ?