mirror of
https://github.com/silverstripe/silverstripe-translatable
synced 2024-10-22 09:05:59 +00:00
BUG Redirect on mixed locale/record URLs
Avoids e.g. the pages tree showing two languages at once.
This commit is contained in:
parent
1a4b284b32
commit
7e1b7a6240
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user