Permalink
Browse files

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
  • Loading branch information...
jthomerson committed Feb 2, 2012
1 parent 0085876 commit d8747154b352e7aa5abc0b88cadbf9838968d7cc
Showing with 17 additions and 7 deletions.
  1. +10 −0 core/control/RootURLController.php
  2. +7 −7 core/model/SiteTree.php
@@ -53,6 +53,16 @@ public static function get_homepage_link() {
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.
*
View
@@ -180,9 +180,9 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
/**
* @see SiteTree::set_create_defaultpages()
- */
+ */
private static $create_default_pages = true;
-
+
/**
* This controls whether of not extendCMSFields() is called by getCMSFields.
*/
@@ -231,7 +231,7 @@ public static function disable_nested_urls() {
public static function set_create_default_pages($option = true) {
self::$create_default_pages = $option;
}
-
+
/**
* Fetches the {@link SiteTree} object that maps to a link.
*
@@ -618,8 +618,8 @@ public function Breadcrumbs($maxDepth = 20, $unlinked = false, $stopAtPageType =
&& (!$maxDepth || sizeof($parts) < $maxDepth)
&& (!$stopAtPageType || $page->ClassName != $stopAtPageType)
) {
- if($showHidden || $page->ShowInMenus || ($page->ID == $this->ID)) {
- if($page->URLSegment == 'home') $hasHome = true;
+ if($showHidden || $page->ShowInMenus || ($page->ID == $this->ID)) {
+ $title = $this->getBreadcrumbTitle($page);
if(($page->ID == $this->ID) || $unlinked) {
$parts[] = Convert::raw2xml($page->Title);
} else {
@@ -1287,11 +1287,11 @@ function requireDefaultRecords() {
// default pages
if($this->class == 'SiteTree' && self::$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', '<p>Welcome to SilverStripe! This is the default homepage. You can edit this page by opening <a href="admin/">the CMS</a>. You can now access the <a href="http://doc.silverstripe.org">developer documentation</a>, or begin <a href="http://doc.silverstripe.org/doku.php?id=tutorials">the tutorials.</a></p>');
- $homepage->URLSegment = 'home';
+ $homepage->URLSegment = RootURLController::get_default_homepage_link();
$homepage->Status = 'Published';
$homepage->Sort = 1;
$homepage->write();

0 comments on commit d874715

Please sign in to comment.