Note, I've got no idea behind the logic of should_be_on_root - the change is a best guess based on the fact that `Translatable` doesn't exist in SS4 yet
This commit is contained in:
Al Twohill 2019-03-28 20:40:33 +13:00
parent 023248f867
commit dcfb502e5c

View File

@ -11,7 +11,6 @@ use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Resettable; use SilverStripe\Core\Resettable;
use SilverStripe\ORM\DB; use SilverStripe\ORM\DB;
use Translatable;
class RootURLController extends Controller implements Resettable class RootURLController extends Controller implements Resettable
{ {
@ -41,34 +40,10 @@ class RootURLController extends Controller implements Resettable
public static function get_homepage_link() public static function get_homepage_link()
{ {
if (!self::$cached_homepage_link) { if (!self::$cached_homepage_link) {
// @todo Move to 'homepagefordomain' module $link = Config::inst()->get(__CLASS__, 'default_homepage_link');
if (class_exists('HomepageForDomainExtension')) { singleton(__CLASS__)->extend('updateHomepageLink', $link);
$host = str_replace('www.', null, $_SERVER['HTTP_HOST']);
$candidates = SiteTree::get()->where(array(
'"SiteTree"."HomepageForDomain" LIKE ?' => "%$host%"
));
if ($candidates) {
foreach ($candidates as $candidate) {
if (preg_match('/(,|^) *' . preg_quote($host) . ' *(,|$)/', $candidate->HomepageForDomain)) {
self::$cached_homepage_link = trim($candidate->RelativeLink(true), '/');
}
}
}
}
if (!self::$cached_homepage_link) {
// TODO Move to 'translatable' module
if (class_exists('Translatable')
&& SiteTree::has_extension('Translatable')
&& $link = Translatable::get_homepage_link_by_locale(Translatable::get_current_locale())
) {
self::$cached_homepage_link = $link; self::$cached_homepage_link = $link;
} else {
self::$cached_homepage_link = Config::inst()->get('SilverStripe\\CMS\\Controllers\\RootURLController', 'default_homepage_link');
} }
}
}
return self::$cached_homepage_link; return self::$cached_homepage_link;
} }
@ -81,16 +56,7 @@ class RootURLController extends Controller implements Resettable
*/ */
public static function should_be_on_root(SiteTree $page) public static function should_be_on_root(SiteTree $page)
{ {
if (!self::$is_at_root && self::get_homepage_link() == trim($page->RelativeLink(true), '/')) { return (!self::$is_at_root && self::get_homepage_link() == trim($page->RelativeLink(true), '/'));
return !(
class_exists('Translatable')
&& $page->hasExtension('Translatable')
&& $page->Locale
&& $page->Locale != Translatable::default_locale()
);
}
return false;
} }
/** /**