DomainLanguageOverrider::__construct(): Argument #1 ($current_user) must be of type AccountProxyInterface

Created on 19 September 2023, over 1 year ago

Problem/Motivation

The commit that fixed the issue in πŸ“Œ \Drupal calls should be avoided in classes, use dependency injection instead Fixed 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.
πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States bburg Washington D.C.

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @bburg
  • Status changed to Needs review over 1 year ago
  • Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    Waiting for branch to pass
  • πŸ‡ΊπŸ‡ΈUnited States bburg Washington D.C.

    Patch seems to prevent the errors. Not entirely sure if it fixes the original problem in the other issue.

  • Status changed to Needs work over 1 year ago
  • πŸ‡΅πŸ‡­Philippines kenyoOwen

    Hi 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.

  • Status changed to Needs review over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States bburg Washington D.C.

    KenyoOwen, 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.

  • πŸ‡ΊπŸ‡ΈUnited States bburg Washington D.C.
  • πŸ‡ΊπŸ‡ΈUnited States bburg Washington D.C.

    Not 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:

    Fatal error: Uncaught Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException: Circular reference detected for service "entity_type.manager", path: "user_last_access_subscriber -> entity_type.manager -> string_translation -> string_translator.locale.lookup -> config.factory -> domain_language.overrider -> domain.negotiator". in /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php:147
    

    domain.negotiator was one of the arguments added to the overrider class in this issue.

  • Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    Waiting for branch to pass
  • πŸ‡ΊπŸ‡ΈUnited States bburg Washington D.C.

    To 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...

  • Status changed to RTBC 11 months ago
  • πŸ‡ΊπŸ‡ΈUnited States banoodle San Francisco, CA

    Patch #7 works beautifully for me - thank you!

  • Status changed to Needs review 10 months ago
  • πŸ‡³πŸ‡±Netherlands mike.vindicate

    Attached 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()

  • πŸ‡³πŸ‡±Netherlands mike.vindicate

    Forgot to add the services part in #9, re-added in this patch.

  • First commit to issue fork.
  • Merge request !15apply patch modifications β†’ (Open) created by GuillaumePacilly
  • Pipeline finished with Success
    3 months ago
    Total: 137s
    #290529
  • πŸ‡«πŸ‡·France GuillaumePacilly

    Applied patch modifications into a MR and cleaned up references and annotations.

  • Pipeline finished with Success
    3 months ago
    Total: 131s
    #290542
  • Pipeline finished with Success
    3 months ago
    Total: 131s
    #290545
  • First commit to issue fork.
Production build 0.71.5 2024