diff --git a/src/Plugin/GraphQL/DataProducer/ContextLanguage.php b/src/Plugin/GraphQL/DataProducer/ContextLanguage.php index 32afc27b54fe01ce96eafb6f4c10ea8b15058317..11d2b97575ccb788fbf080b8f256820136e68f49 100644 --- a/src/Plugin/GraphQL/DataProducer/ContextLanguage.php +++ b/src/Plugin/GraphQL/DataProducer/ContextLanguage.php @@ -68,7 +68,7 @@ class ContextLanguage extends DataProducerPluginBase implements ContainerFactory * * It can do weird things if changing language mid-query. * - * @param string|null $language + * @param string|null $langcode * The language to resolve the url in. * @param \Drupal\graphql\GraphQL\Execution\FieldContext $context * The cache context. @@ -76,14 +76,20 @@ class ContextLanguage extends DataProducerPluginBase implements ContainerFactory * @return string|null * The language in use. */ - public function resolve(?string $language, FieldContext $context): ?string { + public function resolve(?string $langcode, FieldContext $context): ?string { + + if ($langcode && $this->languageManager->isMultilingual()) { + + $language = $this->languageManager->getLanguage($langcode); + if ($language) { + $context->setContextLanguage($langcode); + $this->languageManager->setConfigOverrideLanguage($language); + } - if ($language && $this->languageManager->isMultilingual()) { - $context->setContextLanguage($language); $this->languageManager->reset(); } - return $language; + return $langcode; } }