Modules can override the values in configuration objects. As described in Configuration override system / Providing overrides from modules, a module needs to implement a service tagged config.factory.override. The class used for the service needs to implement ConfigFactoryOverrideInterface
, as the example given in the documentation does.
services:
config_example.overrider:
class: Drupal\config_example\Config\ConfigExampleOverrides
tags:
- {name: config.factory.override, priority: 5}
namespace Drupal\config_example\Config;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Config\ConfigFactoryOverrideInterface;
use Drupal\Core\Config\StorageInterface;
/**
* Example configuration override.
*/
class ConfigExampleOverrides implements ConfigFactoryOverrideInterface {
/**
* {@inheritdoc}
*/
public function loadOverrides($names) {
$overrides = [];
if (in_array('system.site', $names)) {
$overrides['system.site'] = ['name' => 'Overridden site name!'];
}
return $overrides;
}
/**
* {@inheritdoc}
*/
public function getCacheSuffix() {
return 'ConfigExampleOverrider';
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata($name) {
return new CacheableMetadata();
}
/**
* {@inheritdoc}
*/
public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) {
return NULL;
}
}
Keep in mind that the value in the settings.php file always override the module values. For a module to set a configuration value, the settings.php file needs not to set it.