Document how 'Overriding Configuration' is intended to work.

Created on 6 May 2025, 29 days ago

I have trouble understanding how 'Overriding Configuration' is intended to work.

Suppose I have

$config = \Drupal::config('my_module.settings')->get('my_setting');

and that 'my_setting' has the value of 'abcdef'

This is what I did:

  1. I created a Key using the File option. I now have a key file somewhere on my filesystem with 'abcdef' in it.
  2. Next, I created a Key override called 'my_key' for ''my_setting' using this Key. I ticked the box 'Clear overridden value'

Next, the confusion starts. When I run this code

$config = \Drupal::config('my_module.settings')->get('my_setting');

Should I expect $config now to be empty (as I selected 'Clear overridden value') or 'abcdef', as it is set in the key value?

I hope the latter, but apparently it is the former, as above code renders $config empty.

However, using below code, I am able to get 'abcdef' from my key file.

$config = \Drupal::service('key.repository')->getKey('my_key')->getKeyValue();

Is this how this module is intended to work? If so, I suggest we find a different term for 'Overriding', e.g. 'Replacing'. To me, underlying code should not have to be adapted to obtain 'overridden' values.

๐Ÿ“Œ Task
Status

Active

Version

4.0

Component

Documentation

Created by

๐Ÿ‡ณ๐Ÿ‡ฑNetherlands koosvdkolk

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

Comments & Activities

  • Issue created by @koosvdkolk
  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands koosvdkolk
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia rajeshreeputra Pune

    I think we can make things a bit clearer for users by updating the label.
    Right now, "Clear overridden value" might leave some people unsure about what it actually does. I suggest changing it to "Clear overridden value from the configuration item." This way, itโ€™s more specific and helps users understand exactly what will happen when they click it.

  • @rajeshreeputra opened merge request.
  • @rajeshreeputra opened merge request.
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia rajeshreeputra Pune
  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands koosvdkolk

    Thanks!

    But should $config = \Drupal::config('my_module.settings')->get('my_setting'); give me my setting value when this module is in place?

    Or should I use $config = \Drupal::service('key.repository')->getKey('my_key')->getKeyValue();?

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia rajeshreeputra Pune

    But should $config = \Drupal::config('my_module.settings')->get('my_setting'); give me my setting value when this module is in place?

    This should not give the value, as value in config now cleared by the override.

    Or should I use $config = \Drupal::service('key.repository')->getKey('my_key')->getKeyValue();?

    This should give the value from the key.

  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands koosvdkolk

    Ok thanks!

    So when I read

    The Drupal 8 version of Key provides the ability to override any configuration value with a key. This allows site administrators to store configuration values in a more secure method than in the database or in settings.php.

    • * Enter a name for the override
    • * Select the specific configuration item you wish to override
    • * Select an existing key that provides the value to be used; if the key doesn't exist, you'll need to create it
    • * Check "Clear overridden value" to clear any existing value for the overridden configuration item; this is important to make sure potentially sensitive data is removed from the configuration; if for some reason, you don't want to clear the value, uncheck this field
    • * Click "Save"

    My expectation is that

    $config = \Drupal::config('my_module.settings')->get('my_setting');

    will still work, as above description does not mention anything about me having to alter my code and 'overriding' feels to me like 'taking over existing functionality without API changes'. So in my mind, the Key module would somehow intercept the 'get('my_setting')'-part, and return the value stored in the Key in stead of the emptied config.

    What would be the exact use case of the current implementation? Why would I not just discard the whole config and replace it with Keys?

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia rajeshreeputra Pune

    Sorry for the confusion caused by previous comment.

    I would like to share a use case to clarify the expected behavior regarding configuration overrides with the Key module.

    For example, let's say we have the following configuration:

    my_module.settings:
      key1: value1
      secret: secret_value
    
    • We override the secret value using the Key module.
    • When we access the configuration value in code as:
      $config = \Drupal::config('my_module.settings')->get('secret'); the returned value should be the overridden secret from the Key module, i.e., secret_value from the key configuration.
    • When we access the configuration value in CLI:
      ./vendor/bin/drush cget my_module.settings secret the returned value should be null.
    • Even when accessing via configuration export it should be null, in my_module.settings.yml file.
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States japerry KVUO
Production build 0.71.5 2024