Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Mullenger committed Dec 21, 2010
0 parents commit 91dc5db
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
@@ -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
------------

10 changes: 10 additions & 0 deletions _config.php
@@ -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');
55 changes: 55 additions & 0 deletions code/HoldingPage.php
@@ -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();
}

}
?>
19 changes: 19 additions & 0 deletions code/HoldingPageConfigDecorator.php
@@ -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);
}

}
23 changes: 23 additions & 0 deletions code/HoldingPageControllerExtension.php
@@ -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;
}
}
2 changes: 2 additions & 0 deletions templates/Layout/HoldingPage.ss
@@ -0,0 +1,2 @@
<h1>$Title</h1>
$Content

0 comments on commit 91dc5db

Please sign in to comment.