/** * Return a link to the homepage for the current locale * * @return string link to the homepage for the current locale */ public function BaseLinkForLocale() { return Controller::join_links(Director::baseURL(), LanguagePrefix::get_prefix($this->owner->Locale), '/'); }
/** * Return a link to the homepage for the current locale * * @return string link to the homepage for the current locale */ public function BaseLinkForLocale() { $prefix = LanguagePrefix::get_prefix($this->owner->Locale); $prefixLink = $prefix ? $prefix . '/' : ''; return Controller::join_links(Director::baseURL(), $prefixLink); }
public function getNestedController() { // Check Translatable dependency if (!class_exists('Translatable') || !SiteTree::has_extension('Translatable') && !SiteTree::has_extension('LanguagePrefixTranslatable')) { throw new Exception('Dependency error: the LanguagePrefix module expects the Translatable module.'); } // No prefix means we're on root. set the prefix to the default if (!($prefix = $this->request->param('Prefix'))) { $prefix = LanguagePrefix::get_prefix(); } // No locale means the prefix might be an old URL... if (!$this->setLocale($prefix)) { $this->Locale = Translatable::default_locale(); return $this->showPageNotFound(); } else { $URLSegment = $this->request->param('URLSegment'); } // Empty URLSegment? Try and get the homepage for the current locale if (empty($URLSegment)) { PrefixRootURLController::set_is_at_root(); // get the homepage from the defaul homepage Translation Group $URLSegment = LanguagePrefix::get_homepage_link_by_locale($this->locale); // if no homepage is found in the default translation group for this locale // use the first page in the tree instead if (empty($URLSegment)) { //@TODO: make 3.0 $sitetree = SiteTree::get()->filter(array('ParentID' => '0', 'Locale' => $this->locale))->sort('Sort')->First(); if ($sitetree) { $URLSegment = $sitetree->URLSegment; } else { // last resort $URLSegment = self::$default_homepage_link; } } } // We have an URLSegment: find the page with this segment - within the current locale // In the original ModelAsController the locale filter is disabled for this query, // meaning /nl/englishHomePage/ will be found and be redirected later on // to /en/englishHomePage/ where I'd rather have a 404!! Translatable::enable_locale_filter(); // make sure multibyte urls are supported $sitetree = DataObject::get_one('SiteTree', sprintf('"SiteTree"."URLSegment" = \'%s\' %s', Convert::raw2sql(rawurlencode($URLSegment)), SiteTree::config()->nested_urls ? 'AND "SiteTree"."ParentID" = 0' : null)); // As in the original ModelAsController: if no page can be found, check if it // has been renamed or relocated - again: within the current locale!!! // If the current $URLSegment refers to an 'old page', do a 302 redirect to the // current version (this works for bookmarked pages) // Note: for this the find_old_page() function needs to be localized as well to // find_old_page_localized() if (empty($sitetree)) { if ($redirect = self::find_old_page_localized($URLSegment)) { $params = $this->request->getVars(); if (isset($params['url'])) { unset($params['url']); } $this->response = new SS_HTTPResponse(); $this->response->redirect(Controller::join_links($redirect->Link(Controller::join_links($this->request->param('Action'), $this->request->param('ID'), $this->request->param('OtherID'))), $params ? '?' . http_build_query($params) : null), 301); return $this->response; } // all is now lost! return $this->showPageNotFound(); } // This we don't really need anymore... // Enforce current locale setting to the loaded SiteTree object // if($sitetree->Locale) Translatable::set_current_locale($sitetree->Locale); if (isset($_REQUEST['debug'])) { Debug::message("Using record #{$sitetree->ID} of type {$sitetree->class} with link {$sitetree->Link()}"); } return self::controller_for($sitetree, $this->request->param('Action')); }