Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By mikelutz on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
9.0.x
Introduced in version:
9.0.0
Issue links:
Description:
The app.root
and site.path
services have been converted to container parameters.
The services are deprecated in Drupal 9 and will be removed in Drupal 10.
Service YAML file will need to be updated. For example:
Before
cache.backend.apcu:
class: Drupal\Core\Cache\ApcuBackendFactory
arguments: ['@app.root', '@site.path', '@cache_tags.invalidator.checksum']
After
cache.backend.apcu:
class: Drupal\Core\Cache\ApcuBackendFactory
arguments: ['%app.root%', '%site.path%', '@cache_tags.invalidator.checksum']
How to be cross-compatible with Drupal 8, 9 and 10?
This is how you can be compatible with Drupal 8 and 9 while not triggering any Drupal 10 deprecation notices (i.e. be compatible with Drupal 8, 9 and 10):
diff --git a/cdn.services.yml b/cdn.services.yml
index da9db27..c12756d 100644
--- a/cdn.services.yml
+++ b/cdn.services.yml
@@ -5,7 +5,7 @@ services:
cdn.file_url_generator:
class: Drupal\cdn\File\FileUrlGenerator
- arguments: ['@app.root', '@stream_wrapper_manager', '@request_stack', '@private_key', '@cdn.settings']
+ arguments: ['%app.root%', '@stream_wrapper_manager', '@request_stack', '@private_key', '@cdn.settings']
# Event subscribers.
cdn.config_subscriber:
diff --git a/src/CdnServiceProvider.php b/src/CdnServiceProvider.php
index aec1a4b..365b133 100644
--- a/src/CdnServiceProvider.php
+++ b/src/CdnServiceProvider.php
@@ -29,6 +29,12 @@ class CdnServiceProvider implements ServiceProviderInterface {
// banned, without having to run this middleware.
->addTag('http_middleware', ['priority' => 230]);
}
+ // @todo Delete this when dropping Drupal 8 support in https://www.drupal.org/project/cdn/issues/3103682.
+ if (version_compare(\Drupal::VERSION, '9.0', '<')) {
+ // @see https://www.drupal.org/project/drupal/issues/3074585
+ $container->getDefinition('cdn.file_url_generator')
+ ->setArgument(0, new Reference('app.root'));
+ }
}
/**
Impacts:
Site builders, administrators, editors
Module developers
Distribution developers
Comments
Alternative way to get active site now that site.path deprecated
If you find yourself on this change record page, wondering how to find the active site in a multisite set-up and you're used to using the deprecated
site.path
service. Below is a way to get the active site, using the static functionDrupalKernel::findSitePath()
.Another way to retrieve path
Another way to retrieve path by using parameter directly from container: