Skip to content
Snippets Groups Projects
Commit 1bc580d9 authored by Jon Minder's avatar Jon Minder
Browse files

Issue #3373726 by webadpro, shabana.navas, dulnan, ayalon: Single language...

Issue #3373726 by webadpro, shabana.navas, dulnan, ayalon: Single language site causes issue with Route
parent fe83924f
No related branches found
No related tags found
No related merge requests found
......@@ -11,10 +11,9 @@ use Drupal\Core\Path\PathValidatorInterface;
use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Url;
use Drupal\graphql_core_schema\GraphQL\Buffers\SubRequestBuffer;
use Drupal\graphql\GraphQL\Execution\FieldContext;
use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase;
use Drupal\language\LanguageNegotiatorInterface;
use Drupal\graphql_core_schema\GraphQL\Buffers\SubRequestBuffer;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
use GraphQL\Deferred;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -174,7 +173,7 @@ class Route extends DataProducerPluginBase implements ContainerFactoryPluginInte
$pluginId,
$pluginDefinition,
PathValidatorInterface $pathValidator,
LanguageNegotiatorInterface $languageNegotiator,
$languageNegotiator,
LanguageManagerInterface $languageManager,
$redirectRepository,
InboundPathProcessorInterface $pathProcessor,
......@@ -233,14 +232,12 @@ class Route extends DataProducerPluginBase implements ContainerFactoryPluginInte
$negotiatedLangcode = $currentLanguage;
$redirectStorage = $this->entityTypeManger->getStorage('redirect');
// Fix for #3373726: Setups without URL based language negotiation.
if ($this->languageNegotiator->isNegotiationMethodEnabled('language-url')) {
if ($this->languageNegotiator && $this->languageNegotiator->isNegotiationMethodEnabled('language-url')) {
$currentUser = \Drupal::currentUser();
$this->languageNegotiator->setCurrentUser($currentUser);
// Determine the language from the provided url string.
$negotiator = $this->languageNegotiator->getNegotiationMethodInstance('language-url');
// @TODO: Also related to #3373726, current user was missing on
// the negotiator, but that seems wrong. Needs further investigation.
$currentUser = \Drupal::currentUser();
$negotiator->setCurrentUser($currentUser);
$negotiatedUrlLangcode = $negotiator->getLangcode($request);
if ($negotiatedUrlLangcode) {
$negotiatedLangcode = $negotiatedUrlLangcode;
......@@ -251,11 +248,13 @@ class Route extends DataProducerPluginBase implements ContainerFactoryPluginInte
$target_url = $url->toString(TRUE)->getGeneratedUrl();
// if language detection is domain based, remove domain from $target_url
$lang_n_config = $this->configFactory->get('language.negotiation');
if ($lang_n_config->get('url.source') == LanguageNegotiationUrl::CONFIG_DOMAIN) {
$lang_domain = $lang_n_config->get('url.domains.' . $negotiatedLangcode);
$target_url = str_replace(['http://', 'https://'], '', $target_url);
$target_url = str_replace($lang_domain, '', $target_url);
if ($this->languageNegotiator) {
$lang_n_config = $this->configFactory->get('language.negotiation');
if ($lang_n_config->get('url.source') == LanguageNegotiationUrl::CONFIG_DOMAIN) {
$lang_domain = $lang_n_config->get('url.domains.' . $negotiatedLangcode);
$target_url = str_replace(['http://', 'https://'], '', $target_url);
$target_url = str_replace($lang_domain, '', $target_url);
}
}
// Check if the URL has an alias and should be redirected.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment