From 3c3b27d3cb46ab08bc5a9cd7c5e1cfb25bf67d53 Mon Sep 17 00:00:00 2001 From: Jeremy Thomerson Date: Fri, 3 Feb 2012 03:24:00 +0000 Subject: [PATCH] ENHANCEMENT Allow the homepage to have a different URL If you changed the URL segment for your homepage to anything other than 'home' a new homepage would be created every time you ran a dev/build. This commit allows you to call RootURLController::set_default_homepage_link('something'); to change the URL segment for your homepage to 'something'. After doing this the dev/build process will no longer create a homepage if you already have a page with 'something' as the URL segment. There was a discussion of needing this at http://www.silverstripe.org/general-questions/show/12253 --- code/controllers/RootURLController.php | 10 ++++++++++ code/model/SiteTree.php | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/code/controllers/RootURLController.php b/code/controllers/RootURLController.php index 5d01e32d..56aef850 100644 --- a/code/controllers/RootURLController.php +++ b/code/controllers/RootURLController.php @@ -54,6 +54,16 @@ class RootURLController extends Controller { return self::$cached_homepage_link; } + /** + * Set the URL Segment used for your homepage when it is created by dev/build. + * This allows you to use home page URLs other than the default "home". + * + * @param string $urlsegment the URL segment for your home page + */ + public static function set_default_homepage_link($urlsegment = "home") { + self::$default_homepage_link = $urlsegment; + } + /** * Gets the link that denotes the homepage if there is not one explicitly defined for this HTTP_HOST value. * diff --git a/code/model/SiteTree.php b/code/model/SiteTree.php index c6cc9c9f..94ef9062 100644 --- a/code/model/SiteTree.php +++ b/code/model/SiteTree.php @@ -1328,11 +1328,11 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid // default pages if($this->class == 'SiteTree' && self::get_create_default_pages()) { - if(!SiteTree::get_by_link('home')) { + if(!SiteTree::get_by_link(RootURLController::get_default_homepage_link())) { $homepage = new Page(); $homepage->Title = _t('SiteTree.DEFAULTHOMETITLE', 'Home'); $homepage->Content = _t('SiteTree.DEFAULTHOMECONTENT', '

Welcome to SilverStripe! This is the default homepage. You can edit this page by opening the CMS. You can now access the developer documentation, or begin the tutorials.

'); - $homepage->URLSegment = 'home'; + $homepage->URLSegment = RootURLController::get_default_homepage_link(); $homepage->Sort = 1; $homepage->write(); $homepage->publish('Stage', 'Live');