Loading core/modules/language/src/ConfigurableLanguageManager.php +16 −0 Original line number Diff line number Diff line Loading @@ -408,7 +408,23 @@ public function getLanguageSwitchLinks($type, Url $url) { $reflector = new \ReflectionClass($method['class']); if ($reflector->implementsInterface('\Drupal\language\LanguageSwitcherInterface')) { $original_languages = $this->negotiatedLanguages; $result = $this->negotiator->getNegotiationMethodInstance($method_id)->getLanguageSwitchLinks($this->requestStack->getCurrentRequest(), $type, $url); $result = array_filter($result, function (array $link): bool { $url = $link['url'] ?? NULL; $language = $link['language'] ?? NULL; if ($language instanceof LanguageInterface) { $this->negotiatedLanguages[LanguageInterface::TYPE_CONTENT] = $language; $this->negotiatedLanguages[LanguageInterface::TYPE_INTERFACE] = $language; } try { return $url instanceof Url && $url->access(); } catch (\Exception $e) { return FALSE; } }); $this->negotiatedLanguages = $original_languages; if (!empty($result)) { // Allow modules to provide translations for specific links. Loading core/modules/language/src/Plugin/Block/LanguageBlock.php +1 −2 Original line number Diff line number Diff line Loading @@ -83,9 +83,8 @@ protected function blockAccess(AccountInterface $account) { */ public function build() { $build = []; $route_name = $this->pathMatcher->isFrontPage() ? '<front>' : '<current>'; $type = $this->getDerivativeId(); $links = $this->languageManager->getLanguageSwitchLinks($type, Url::fromRoute($route_name)); $links = $this->languageManager->getLanguageSwitchLinks($type, Url::fromRouteMatch(\Drupal::routeMatch())); if (isset($links->links)) { $build = [ Loading core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php +1 −1 Original line number Diff line number Diff line Loading @@ -139,7 +139,7 @@ public function processOutbound($path, &$options = [], Request $request = NULL, public function getLanguageSwitchLinks(Request $request, $type, Url $url) { $links = []; $query = []; parse_str($request->getQueryString(), $query); parse_str($request->getQueryString() ?? '', $query); foreach ($this->languageManager->getNativeLanguages() as $language) { $langcode = $language->getId(); Loading core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php +2 −1 Original line number Diff line number Diff line Loading @@ -125,10 +125,11 @@ public function processOutbound($path, &$options = [], Request $request = NULL, */ public function getLanguageSwitchLinks(Request $request, $type, Url $url) { $links = []; $query = []; parse_str($request->getQueryString() ?? '', $query); $config = $this->config->get('language.negotiation')->get('session'); $param = $config['parameter']; $language_query = $_SESSION[$param] ?? $this->languageManager->getCurrentLanguage($type)->getId(); $query = $request->query->all(); foreach ($this->languageManager->getNativeLanguages() as $language) { $langcode = $language->getId(); Loading core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php +2 −1 Original line number Diff line number Diff line Loading @@ -195,7 +195,8 @@ public function processOutbound($path, &$options = [], Request $request = NULL, */ public function getLanguageSwitchLinks(Request $request, $type, Url $url) { $links = []; $query = $request->query->all(); $query = []; parse_str($request->getQueryString() ?? '', $query); foreach ($this->languageManager->getNativeLanguages() as $language) { $links[$language->getId()] = [ Loading Loading
core/modules/language/src/ConfigurableLanguageManager.php +16 −0 Original line number Diff line number Diff line Loading @@ -408,7 +408,23 @@ public function getLanguageSwitchLinks($type, Url $url) { $reflector = new \ReflectionClass($method['class']); if ($reflector->implementsInterface('\Drupal\language\LanguageSwitcherInterface')) { $original_languages = $this->negotiatedLanguages; $result = $this->negotiator->getNegotiationMethodInstance($method_id)->getLanguageSwitchLinks($this->requestStack->getCurrentRequest(), $type, $url); $result = array_filter($result, function (array $link): bool { $url = $link['url'] ?? NULL; $language = $link['language'] ?? NULL; if ($language instanceof LanguageInterface) { $this->negotiatedLanguages[LanguageInterface::TYPE_CONTENT] = $language; $this->negotiatedLanguages[LanguageInterface::TYPE_INTERFACE] = $language; } try { return $url instanceof Url && $url->access(); } catch (\Exception $e) { return FALSE; } }); $this->negotiatedLanguages = $original_languages; if (!empty($result)) { // Allow modules to provide translations for specific links. Loading
core/modules/language/src/Plugin/Block/LanguageBlock.php +1 −2 Original line number Diff line number Diff line Loading @@ -83,9 +83,8 @@ protected function blockAccess(AccountInterface $account) { */ public function build() { $build = []; $route_name = $this->pathMatcher->isFrontPage() ? '<front>' : '<current>'; $type = $this->getDerivativeId(); $links = $this->languageManager->getLanguageSwitchLinks($type, Url::fromRoute($route_name)); $links = $this->languageManager->getLanguageSwitchLinks($type, Url::fromRouteMatch(\Drupal::routeMatch())); if (isset($links->links)) { $build = [ Loading
core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php +1 −1 Original line number Diff line number Diff line Loading @@ -139,7 +139,7 @@ public function processOutbound($path, &$options = [], Request $request = NULL, public function getLanguageSwitchLinks(Request $request, $type, Url $url) { $links = []; $query = []; parse_str($request->getQueryString(), $query); parse_str($request->getQueryString() ?? '', $query); foreach ($this->languageManager->getNativeLanguages() as $language) { $langcode = $language->getId(); Loading
core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php +2 −1 Original line number Diff line number Diff line Loading @@ -125,10 +125,11 @@ public function processOutbound($path, &$options = [], Request $request = NULL, */ public function getLanguageSwitchLinks(Request $request, $type, Url $url) { $links = []; $query = []; parse_str($request->getQueryString() ?? '', $query); $config = $this->config->get('language.negotiation')->get('session'); $param = $config['parameter']; $language_query = $_SESSION[$param] ?? $this->languageManager->getCurrentLanguage($type)->getId(); $query = $request->query->all(); foreach ($this->languageManager->getNativeLanguages() as $language) { $langcode = $language->getId(); Loading
core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php +2 −1 Original line number Diff line number Diff line Loading @@ -195,7 +195,8 @@ public function processOutbound($path, &$options = [], Request $request = NULL, */ public function getLanguageSwitchLinks(Request $request, $type, Url $url) { $links = []; $query = $request->query->all(); $query = []; parse_str($request->getQueryString() ?? '', $query); foreach ($this->languageManager->getNativeLanguages() as $language) { $links[$language->getId()] = [ Loading