Problem/Motivation
The commit that fixed the issue in #3370924: \Drupal calls should be avoided in classes, use dependency injection instead seems to have caused an error. In that, cslevy comments:
Fatal error: Uncaught TypeError: Drupal\domain_language\DomainLanguageOverrider::__construct(): Argument #1 ($current_user) must be of type Drupal\Core\Session\AccountProxyInterface, Drupal\Core\Config\CachedStorage given, called in .../web/core/lib/Drupal/Component/DependencyInjection/Container.php on line 259 and defined in .../web/modules/contrib/domain_language/src/DomainLanguageOverrider.php:81
This class is defined in the services in the following way:
domain_language.overrider:
class: Drupal\domain_language\DomainLanguageOverrider
tags:
- { name: config.factory.override, priority: -140 }
arguments: ['@config.storage']
And also the create method was introduced.
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('current_user'),
$container->get('domain.negotiator'),
$container->get('config.factory'),
$container->get('domain_config.overrider')
);
}
We don't need both. I think the dependencies should be defined in the services.yml, and this create method removed.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | domain_language-3388388-10.patch | 3.63 KB | michael.acampora |
| #9 | domain_language-3388388-9.patch | 3.2 KB | michael.acampora |
| #8 | Screenshot 2024-01-19 at 5.21.41 PM.png | 17.78 KB | banoodle |
| #7 | domain_language-3388388-7.patch | 3.71 KB | bburg |
| #3 | with patch.png | 444.38 KB | kenyoowen |
Issue fork domain_language-3388388
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
bburgPatch seems to prevent the errors. Not entirely sure if it fixes the original problem in the other issue.
Comment #3
kenyoowen commentedHi bburg
I reproduced the error by enabling the module and applied your patch but still it has errors. Please see the screenshots attached.
Thank you.
Comment #4
bburgKenyoOwen, I don't believe the error in your screenshot can be attributed to this issue per se, it seems related to this one #3005048: Circular reference detected for service "router.route_provider". But feel free to correct me if you think I'm wrong.
Comment #5
bburgComment #6
bburgNot sure if it's related to the patch, but upon coming back to this same project after a few days, I am getting this error:
domain.negotiator was one of the arguments added to the overrider class in this issue.
Comment #7
bburgTo address the errors in my last comment, I've moved accessing the domain.negotiatior to it's own method, that conditionally checks if it's already available. I was just following the example agentrickard uses in #3005048-16: Circular reference detected for service "router.route_provider". Which seems to have stopped the error for me, although I don't really understand why...
Comment #8
banoodle commentedPatch #7 works beautifully for me - thank you!
Comment #9
michael.acampora commentedAttached patch fixes a deprecation for php 8.2 that came in with the last patch, it's a small fix and thanks for the patch in #7 @bburg.
Deprecated function: Creation of dynamic property Drupal\domain_language\DomainLanguageOverrider::$currrentUser is deprecated in Drupal\domain_language\DomainLanguageOverrider->initiateContext()
Comment #10
michael.acampora commentedForgot to add the services part in #9, re-added in this patch.
Comment #13
guillaumepacilly commentedApplied patch modifications into a MR and cleaned up references and annotations.
Comment #15
dtfabio commentedHi everyone,
MR 15 fixed the problem for me on:
Core version 10.3.13
PHP version 8.1.31
MySQL version 8.0.4
Greetings,
Fabio
Comment #16
guiu.rocafort.ferrerTested it and works well
Comment #18
jeroentComment #19
jeroentComment #21
jeroentMerged to 2.0.x-dev. Thanks!