Suggested commit message: Issue #2363351 by chx, larowlan: CMI (or anything cached) can'\''t be used from a Service Provider
.
Problem/Motivation
The cache_factory
service needs %cache_default_bin_backends
. This parameter is added by ListCacheBinsPass
. This runs after service providers which, as a corollary can't use CMI. LanguageServiceProvider is an example which tries to use CMI and abuses the bootstrap config storage to do so because it can't use the normal service. There's a @todo to replace it with config.storage. This issue is about resolving that @todo.
Another example that if you would like to try to access a module's path in a service provider you get a You have requested a non-existent parameter "cache_default_bin_backends".
:
final class MY_MODULE_ServiceProvider implements ServiceProviderInterface {
/**
* {@inheritdoc}
*/
public function register(ContainerBuilder $container): void {
/** @var \Drupal\Core\Extension\ModuleHandlerInterface $module_handler */
$module_handler = $container->get('module_handler');
try {
$path = $module_handler->getModule(MY_MODULE)->getPath();
} catch (\Exception $e) {
throw new LogicException('Unable to identify installation path of this module.');
}
}
Proposed resolution
Add cache_default_bin_backends: null
by default and if NULL return NullBackend unconditionally from the CacheBackend.