public function ConfigFilterServiceProvider::alter in Config Filter 8
Modifies existing service definitions.
Parameters
ContainerBuilder $container: The ContainerBuilder whose service definitions can be altered.
Overrides ServiceProviderBase::alter
File
- src/
ConfigFilterServiceProvider.php, line 20
Class
- ConfigFilterServiceProvider
- Service provider to swap out the config sync service.
Namespace
Drupal\config_filterCode
public function alter(ContainerBuilder $container) {
if ($container
->hasDefinition('config.storage.sync')) {
$original = $container
->getDefinition('config.storage.sync');
$id = 'config.storage.sync';
}
elseif ($container
->hasDefinition('config.storage.staging')) {
// For Drupal 8.
$original = $container
->getDefinition('config.storage.staging');
$id = 'config.storage.staging';
}
else {
throw new ServiceNotFoundException('config_filter.storage.original', 'config.storage.sync');
}
// Save the original service so that we can use it in the factory.
$container
->setDefinition('config_filter.storage.original', $original);
$definition = new Definition(FilteredStorage::class);
$definition
->setFactory([
new Reference('config_filter.storage_factory'),
'getSync',
]);
$container
->setDefinition($id, $definition);
}