From 7e1b7a624015176932dc47cd421239fe8b4e01f0 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 16 Jul 2012 23:35:28 +0200 Subject: [PATCH] BUG Redirect on mixed locale/record URLs Avoids e.g. the pages tree showing two languages at once. --- .../TranslatableCMSMainExtension.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/code/controller/TranslatableCMSMainExtension.php b/code/controller/TranslatableCMSMainExtension.php index 9ae93d8..876611c 100644 --- a/code/controller/TranslatableCMSMainExtension.php +++ b/code/controller/TranslatableCMSMainExtension.php @@ -26,6 +26,27 @@ class TranslatableCMSMainExtension extends Extension { $this->owner->Locale = Translatable::default_locale(); } Translatable::set_current_locale($this->owner->Locale); + + // if a locale is set, it needs to match to the current record + $requestLocale = $req->requestVar("Locale") ? $req->requestVar("Locale") : $req->requestVar("locale"); + $page = $this->owner->currentPage(); + if($requestLocale && $page && $page->Locale != $requestLocale) { + $transPage = $page->getTranslation($requestLocale); + if($transPage) { + Translatable::set_current_locale($transPage->Locale); + return $this->owner->redirect(Controller::join_links( + $this->owner->Link('show'), + $transPage->ID + // ?locale will automatically be added + )); + } else { + // If the record is not translated, redirect to pages overview + return $this->owner->redirect(Controller::join_links( + singleton('CMSPagesController')->Link(), + '?locale=' . $requestLocale + )); + } + } // collect languages for TinyMCE spellchecker plugin. // see http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/spellchecker