BUG Redirect on mixed locale/record URLs

Avoids e.g. the pages tree showing two languages at once.
This commit is contained in:
Ingo Schommer 2012-07-16 23:35:28 +02:00
parent 1a4b284b32
commit 7e1b7a6240

View File

@ -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