diff --git a/core/lib/Drupal/Component/Plugin/Discovery/DiscoveryInterface.php b/core/lib/Drupal/Component/Plugin/Discovery/DiscoveryInterface.php index 66e6a2ec03..9ae3b695f7 100644 --- a/core/lib/Drupal/Component/Plugin/Discovery/DiscoveryInterface.php +++ b/core/lib/Drupal/Component/Plugin/Discovery/DiscoveryInterface.php @@ -22,7 +22,7 @@ * A plugin definition, or NULL if the plugin ID is invalid and * $exception_on_invalid is FALSE. * - * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException + * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundExceptuion * Thrown if $plugin_id is invalid and $exception_on_invalid is TRUE. */ public function getDefinition($plugin_id, $exception_on_invalid = TRUE); diff --git a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php index 971e907aae..b14f509e5f 100644 --- a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php +++ b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php @@ -117,6 +117,13 @@ public function processOutbound($path, &$options = [], Request $request = NULL, } } } + + // To avoid page cache duplicates, remove the language query if the default + // language is set. + if ($this->currentUser->isAnonymous() && $cache && isset($options['query'][$this->queryParam]) && $options['query'][$this->queryParam] == $default) { + unset($options['query'][$this->queryParam]); + } + return $path; } @@ -142,12 +149,12 @@ public function getLanguageSwitchLinks(Request $request, $type, Url $url) { 'attributes' => ['class' => ['language-link']], 'query' => $query, ]; - if ($language_query != $langcode) { - $links[$langcode]['query'][$param] = $langcode; - } - else { + if ($langcode == $language_query) { $links[$langcode]['attributes']['class'][] = 'session-active'; } + // Always set the language query parameter. It may be removed in + // LanguageNegotiationSession::processOutbound(). + $links[$langcode]['query'][$param] = $langcode; } return $links;