Single language site causes issue with Route.

Created on 10 July 2023, over 1 year ago
Updated 24 January 2024, 10 months ago

Problem/Motivation

Currently, the implementation returns an error if you only have 1 language installed on the site.

Proposed resolution

Add a validation if the site is a multilanguage.

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇨🇦Canada webadpro

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

Comments & Activities

  • Issue created by @webadpro
  • 🇨🇦Canada webadpro

    Error:

    For error #0: TypeError: Drupal\language\LanguageNegotiationMethodBase::setCurrentUser(): Argument #1 ($current_user) must be of type Drupal\Core\Session\AccountInterface, null given, called in /app/web/core/modules/language/src/LanguageNegotiator.php on line 215 in Drupal\language\LanguageNegotiationMethodBase->setCurrentUser() (line 52 of /app/web/core/modules/language/src/LanguageNegotiationMethodBase.php)
    #0 /app/web/core/modules/language/src/LanguageNegotiator.php(215): Drupal\language\LanguageNegotiationMethodBase->setCurrentUser(NULL)
    #1 /app/web/modules/contrib/graphql_core_schema/src/Plugin/GraphQL/DataProducer/Route.php(211): Drupal\language\LanguageNegotiator->getNegotiationMethodInstance('language-url')
    #2 [internal function]: Drupal\graphql_core_schema\Plugin\GraphQL\DataProducer\Route->resolve('/jacestrap', Object(Drupal\graphql\GraphQL\Execution\FieldContext))
    #3 /app/web/modules/contrib/graphql/src/Plugin/GraphQL/DataProducer/DataProducerPluginBase.php(51): call_user_func_array(Array, Array)
    #4 /app/web/modules/contrib/graphql/src/Plugin/GraphQL/DataProducer/DataProducerProxy.php(238): Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase->resolveField(Object(Drupal\graphql\GraphQL\Execution\FieldContext))
    #5 /app/web/modules/contrib/graphql/src/Plugin/GraphQL/DataProducer/DataProducerProxy.php(181): Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerProxy->resolveUncached(Object(Drupal\graphql_core_schema\Plugin\GraphQL\DataProducer\Route), Object(Drupal\graphql\GraphQL\Execution\ResolveContext), Object(Drupal\graphql\GraphQL\Execution\FieldContext))
    #6 /app/web/modules/contrib/graphql/src/GraphQL/Utility/DeferredUtility.php(72): Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerProxy->Drupal\graphql\Plugin\GraphQL\DataProducer\{closure}(Object(Drupal\graphql_core_schema\Plugin\GraphQL\DataProducer\Route))
    #7 /app/web/modules/contrib/graphql/src/Plugin/GraphQL/DataProducer/DataProducerProxy.php(182): Drupal\graphql\GraphQL\Utility\DeferredUtility::returnFinally(Object(Drupal\graphql_core_schema\Plugin\GraphQL\DataProducer\Route), Object(Closure))
  • Status changed to Needs review over 1 year ago
  • 🇮🇳India shabana.navas

    Not sure if this is the correct fix, but maybe we can check to see if it's a multilingual site before calling negotiator.

  • 🇨🇭Switzerland dulnan

    I think the issue comes from the fact that the language-url negotiator is not enabled in a single-language setup, but the data producer still tries to get an instance of it. While this works even if the negotiator is not enabled, it seems that, because it has not been initialized properly by Drupal, the $currentUser on the instance is NULL.

    I have added a check to see if the language-url method is enabled before getting the instance. I think this will also resolve the issue.

    • dulnan committed 3b6cb312 on 1.0.x
      Issue #3373726: Fix route resolving on sites without language-url...
  • 🇨🇦Canada webadpro

    There are still bugs within this commit. Where the languageNegotiator is still being referenced in the code.

  • 🇨🇦Canada webadpro

    I've pushed some code changes which seems to be fixing my issue https://git.drupalcode.org/issue/graphql_core_schema-3373726/-/compare/1...

  • 🇨🇭Switzerland ayalon

    I was able to reproduce both errors:

    • Case: 1: Just a single language installed but language module enabled
    • Case: 2: Language module disabled

    I have fixed both cased and improved the code to support Case 1 and Case 2.

    The fix will be part of the upcoming relase, which will be released soon.

    • ayalon committed 1bc580d9 on 1.0.x
      Issue #3373726 by webadpro, shabana.navas, dulnan, ayalon: Single...
  • Status changed to Fixed 10 months ago
Production build 0.71.5 2024