Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Frank Mullenger
committed
Dec 21, 2010
0 parents
commit 91dc5db
Showing
6 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
SilverStripe Holding Page Module | ||
================================ | ||
|
||
Maintainer Contacts | ||
------------------- | ||
* Frank Mullenger (<frankmullenger@gmail.com>) | ||
|
||
Requirements | ||
------------ | ||
* SilverStripe 2.4 | ||
|
||
Documentation | ||
------------- | ||
|
||
Installation Instructions | ||
------------------------- | ||
|
||
Usage Overview | ||
-------------- | ||
|
||
Known Issues | ||
------------ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
/** | ||
* @package silverstripe-holdingpage | ||
*/ | ||
|
||
//Extend the site config | ||
DataObject::add_extension('SiteConfig', 'HoldingPageConfigDecorator'); | ||
|
||
//Extend the controller | ||
DataObject::add_extension('Page_Controller', 'HoldingPageControllerExtension'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
class HoldingPage extends Page { | ||
|
||
static $db = array( | ||
); | ||
static $has_one = array( | ||
); | ||
static $allowed_children = array( | ||
); | ||
static $has_many = array ( | ||
); | ||
static $defaults = array( | ||
"ShowInMenus" => 0, | ||
"ShowInSearch" => 0 | ||
); | ||
|
||
function getCMSFields() { | ||
$fields = parent::getCMSFields(); | ||
return $fields; | ||
} | ||
|
||
/** | ||
* If a holding page is set then redirect to it, unless current user is an admin | ||
*/ | ||
public static function redirectToHolding() { | ||
|
||
$holdingPage = SiteConfig::current_site_config()->ShowHoldingPage(); | ||
$currentUser = Member::currentUser(); | ||
|
||
if ($holdingPage->exists() | ||
&& $holdingPage instanceof HoldingPage | ||
&& $holdingPage->getExistsOnLive()) { | ||
|
||
//Do not redirect for admin users, allow them to browse the site | ||
if ($currentUser && $currentUser->isAdmin()) { | ||
return; | ||
} | ||
|
||
if (Director::get_current_page() != $holdingPage) { | ||
Director::redirect($holdingPage->Link()); | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
class HoldingPage_Controller extends Page_Controller { | ||
|
||
function init() { | ||
parent::init(); | ||
} | ||
|
||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
class HoldingPageConfigDecorator extends DataObjectDecorator { | ||
|
||
function extraStatics() { | ||
return array( | ||
'has_one' => array( | ||
'ShowHoldingPage' => 'SiteTree', | ||
) | ||
); | ||
} | ||
|
||
public function updateCMSFields(FieldSet &$fields) { | ||
//TODO only get published HoldingPages | ||
$treedropdownfield = new DropdownField("ShowHoldingPageID", "Choose a holding page to display", DataObject::get('HoldingPage')->toDropDownMap()); | ||
$treedropdownfield->setHasEmptyDefault(true); | ||
$fields->addFieldToTab("Root.Main", $treedropdownfield); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
class HoldingPageControllerExtension extends Extension { | ||
|
||
public function onBeforeInit() { | ||
|
||
//Redirect to holding page if necessary | ||
HoldingPage::redirectToHolding(); | ||
} | ||
|
||
/** | ||
* Indicate if we are currently on the holding page | ||
* | ||
* @return Boolean Whether current page is the set holding page | ||
*/ | ||
public function OnHoldingPage() { | ||
$holdingPage = SiteConfig::current_site_config()->ShowHoldingPage(); | ||
|
||
if (Director::get_current_page() == $holdingPage) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>$Title</h1> | ||
$Content |