Problem/Motivation
I'm working right now in a multi-domain / multi-country and multi-language platform based in Drupal 9. I was receiving a WSOD (White Screen of Death) in my local Drupal installation when I was trying to enable the Domain Language Detection and Selection options. It was strange, because the module marked availability for Drupal 9 but it is not working.
Steps to reproduce
Steps
- Enable Domain-related modules in your Drupal installation and create a set of domains.
- Download and enable domain_lang module from [https://www.drupal.org/project/domain_lang](https://www.drupal.org/project/domain_lang), using Composer and drush, as usual.
- Go to path: `/admin/config/domain` and click in Operations, then select "Language detection and selection" for a domain from your domains list.
- You will get a WSOD (White Screen Of Death) in your Drupal installation. When you go to `/admin/reports/dblog` you will see an error just like this:
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException:
You have requested a non-existent service "entity.manager".
in Drupal\Component\DependencyInjection\Container->get()
(line 151 in /var/www/html/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php).
Proposed resolution
This is happening due to a specific change in the last versions of Drupal 8.x: The `entity.manager` service was marked as deprecrated in former versions of Drupal 8.8.x and finally was replaced by the service `entity_type.manager`-> https://api.drupal.org/api/drupal/core%21lib%21Drupal.php/function/Drupa..., just as we can see at: https://api.drupal.org/api/drupal/core!lib!Drupal.php/function/Drupal%3A...
Deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0.
Use \Drupal::entityTypeManager() instead in most cases.
If the needed method is not on \Drupal\Core\Entity\EntityTypeManagerInterface,
see the deprecated \Drupal\Core\Entity\EntityManager
to find the correct interface or service.Remaining tasks
Looking for the use of the deprecated service, I found something in file DomainLangNegotiationConfigureForm.php in the create method, line 83.
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
$entity_manager = $container->get('entity.manager');
$block_storage = $entity_manager->hasHandler('block', 'storage') ? $entity_manager->getStorage('block') : NULL;
Then I made the next change:
public static function create(ContainerInterface $container) {
- $entity_manager = $container->get('entity.manager');
+ $entity_manager = $container->get('entity_type.manager');
this solved the problem and eliminated the Exception and the WOSD in my Drupal installation.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | domain_lang-deprecated-service-for-drupal-9-must-be-replaced-3182720-2.patch | 740 bytes | davidjguru |
Issue fork domain_lang-3182720
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
davidjguruComment #3
davidjguruComment #5
davidjguruComment #6
jhedstromThis works!
Comment #8
antonnaviHello all here!
Thank You for help!
Comment #9
antonnaviComment #11
spuky commentedPlease Make a new Release Dev Version is working with D9 but Release version is not altough it states it does
Comment #12
willeaton commentedYes, please, lets create a new beta version so we don't have to use a dev version in production!