From 27b997f62ed0492552a51bc1ecdc3e515609f4fd Mon Sep 17 00:00:00 2001
From: Willynux <Willynux@1058108.no-reply.drupal.org>
Date: Fri, 3 Oct 2014 13:49:29 +0200
Subject: [PATCH 1/2] Issue #815544 by Willynux: Fix duplicate page cache
 entries

---
 .../LanguageNegotiation/LanguageNegotiationSession.php      | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php
index dc5617d..0efcc6c 100644
--- a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php
+++ b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php
@@ -115,6 +115,13 @@ public function processOutbound($path, &$options = array(), Request $request = N
         }
       }
     }
+
+    // To avoid page cache duplicates, remove the language query if the default
+    // language is set.
+    if (!$this->currentUser->id() && $cache && isset($options['query'][$this->queryParam]) && $options['query'][$this->queryParam] == $default) {
+      unset($options['query'][$this->queryParam]);
+    }
+
     return $path;
   }
 
@@ -137,12 +144,10 @@ function getLanguageSwitchLinks(Request $request, $type, $path) {
         'attributes' => array('class' => array('language-link')),
         'query' => $query,
       );
-      if ($language_query != $langcode) {
-        $links[$langcode]['query'][$param] = $langcode;
-      }
-      else {
+      if ($langcode == $language_query) {
         $links[$langcode]['attributes']['class'][] = 'session-active';
       }
+      $links[$langcode]['query'][$param] = $langcode;
     }
 
     return $links;
-- 
1.9.1


From e476cecc778e5f0bf0cfa9601d6420d009863620 Mon Sep 17 00:00:00 2001
From: Willynux <Willynux@1058108.no-reply.drupal.org>
Date: Fri, 3 Oct 2014 15:09:51 +0200
Subject: [PATCH 2/2] Issue #815544 by Willynux: Fixing duplicate page cache
 entries

---
 .../src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php     | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php
index 0efcc6c..79465bf 100644
--- a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php
+++ b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php
@@ -147,7 +147,9 @@ function getLanguageSwitchLinks(Request $request, $type, $path) {
       if ($langcode == $language_query) {
         $links[$langcode]['attributes']['class'][] = 'session-active';
       }
-      $links[$langcode]['query'][$param] = $langcode;
+      // Always set the language query parameter. It will be removed if
+      // necessary in LanguageNegotiationSession::processOutbound().
+	$links[$langcode]['query'][$param] = $langcode;
     }
 
     return $links;
-- 
1.9.1

