0

I have tried both of the following:

$config['my_module.default']['content'] = 'prepend ' . $config['my_module.default']['content'];
$config['my_module.default']['content'] .= ' append';

but the output was just the text:

prepend 
 append

Any suggestions?

(My site is running Drupal 10.1.4)

3 Answers 3

2

No, it is not possible.

Drupal\Core\Site\Settings::initialize, which is the function that reads settings.php, initializes $config as an empty array. The $config values in settings.php are added as overrides when the configuration system initializes. $config is empty when Drupal reads settings.php.

1

The $config array is just stored in $GLOBALS to be used later when Drupal has a database connection. Overrides are then applied on demand when you request a config object.

What you can do, however, is create a config.factory.override tagged service. This service has access to the existing config data, but you have to load the mutable config to avoid applying config overrides recursively:

$original = \Drupal::configFactory()->getEditable('my_module.default')->getOriginal('content', FALSE);

See https://www.drupal.org/docs/drupal-apis/configuration-api/configuration-override-system#s-providing-overrides-from-modules

0

If you try to print the $config variable , then 'll not print any config that are maintained in the site. It is very early stage of Drupal process ,in which not database connection is established neither service containers, so not possible to get config value in settings.php/settings/local.php file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.