使用自定义配置文件安装Drupal 9,我在"config_sync_directory"数组中的settings.php文件中定义了$settings,以便在安装过程中获取配置文件配置。
是否可以从钩子中以编程方式更改路径?
发布于 2022-05-31 07:47:04
模块可以覆盖配置对象中的值。正如配置覆盖系统/从模块提供重写中所描述的,模块需要实现标记为config.factory.override的服务。用于服务的类需要实现ConfigFactoryOverrideInterface,文档中给出的示例就是这样做的。
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;
}
}请记住,settings.php文件中的值总是覆盖模块值。对于要设置配置值的模块,settings.php文件不需要设置它。
https://drupal.stackexchange.com/questions/311391
复制相似问题