BUGFIX: Get subsites working with 2.3

BUGFIX: Allow creation of sites and templates withou a starting template
FEATURE: Allow Theme dropdown in subsite admin to choose the theme from available themes
This commit is contained in:
Sam Minnee 2008-11-19 23:25:43 +00:00
parent b1ac00bcde
commit b530838b4c
5 changed files with 52 additions and 8 deletions

View File

@ -11,6 +11,7 @@ new SiteTree();
Object::add_extension('ContentController', 'ControllerSubsites');
Object::add_extension('LeftAndMain', 'LeftAndMainSubsites');
Object::add_extension('LeftAndMain', 'ControllerSubsites');
Object::add_extension('Group', 'GroupSubsites');
Object::add_extension('File', 'FileSubsites');
?>

View File

@ -128,6 +128,8 @@ class SiteTreeSubsites extends DataObjectDecorator {
static function contentcontrollerInit($controller) {
// Need to set the SubsiteID to null incase we've been in the CMS
Session::set('SubsiteID', null);
$subsite = Subsite::currentSubsite();
if($subsite && $subsite->Theme) SSViewer::set_theme(Subsite::currentSubsite()->Theme);
}
/**

View File

@ -52,6 +52,24 @@ class Subsite extends DataObject implements PermissionProvider {
self::$allowed_themes = $themes;
}
/**
* Return the themes that can be used with this subsite, as an array of themecode => description
*/
function allowedThemes() {
if($themes = $this->stat('allowed_themes')) {
return ArrayLib::valuekey($themes);
} else {
$themes = array();
foreach(scandir('../themes/') as $theme) {
if($theme[0] == '.') continue;
$theme = strtok($theme,'_');
$themes[$theme] = $theme;
}
ksort($themes);
return $themes;
}
}
/**
* Return the base domain for this set of subsites.
* You can set this by setting Subsite::$Base_domain, otherwise it defaults to HTTP_HOST
@ -96,7 +114,7 @@ class Subsite extends DataObject implements PermissionProvider {
new CheckboxField('DefaultSite', 'Use this subsite as the default site', $this->DefaultSite),
new CheckboxField('IsPublic', 'Can access this subsite publicly?', $this->IsPublic),
new DropdownField('Theme','Theme', ArrayLib::valuekey($this->stat('allowed_themes')), $this->Theme)
new DropdownField('Theme','Theme', $this->allowedThemes(), $this->Theme)
)
),
new HiddenField('ID', '', $this->ID),

View File

@ -62,10 +62,9 @@ class SubsiteAdmin extends GenericDataAdmin {
function AddSubsiteForm() {
$templates = $this->getIntranetTemplates();
$templateArray = array('' => "(No template)");
if($templates) {
$templateArray = $templates->map('ID', 'Title');
} else {
$templateArray = array();
$templateArray = $templateArray + $templates->map('ID', 'Title');
}
return new Form($this, 'AddSubsiteForm', new FieldSet(
@ -104,19 +103,32 @@ class SubsiteAdmin extends GenericDataAdmin {
}
*/
$template = DataObject::get_by_id('Subsite_Template', $data['TemplateID']);
if(isset($data['TemplateID']) && $data['TemplateID']) {
$template = DataObject::get_by_id('Subsite_Template', $data['TemplateID']);
} else {
$template = null;
}
// Create intranet from existing template
switch($data['Type']) {
case 'template':
$intranet = $template->duplicate();
if($template) $intranet = $template->duplicate();
else $intranet = new Subsite_Template();
$intranet->Title = $data['Name'];
$intranet->write();
break;
default:
case 'subsite':
$intranet = $template->createInstance($data['Name'], $data['Subdomain']);
default:
if($template) $intranet = $template->createInstance($data['Name'], $data['Subdomain']);
else {
$intranet = new Subsite();
$intranet->Title = $data['Name'];
$intranet->Subdomain = $data['Subdomain'];
$intranet->write();
}
break;
}

View File

@ -0,0 +1,11 @@
<ul id="MainMenu">
<% control MainMenu %>
<li class="$LinkingMode" id="Menu-$Code"><a href="$Link">$Title</a></li>
<% end_control %>
</ul>
<form id="SubsiteActions">
<fieldset>
$SubsiteList
<span>$ApplicationLogoText</span>
</fieldset>
</form>