silverstripe-subsites/code/SubsiteAdmin.php

93 lines
2.2 KiB
PHP
Raw Normal View History

2007-08-18 13:38:11 +02:00
<?php
/**
* Admin interface to manage and create {@link Subsite} instances.
*
* @package subsites
*/
class SubsiteAdmin extends ModelAdmin {
2007-08-18 13:38:11 +02:00
static $managed_models = array('Subsite');
static $url_segment = 'subsites';
static $menu_title = "Subsites";
static $collection_controller_class = "SubsiteAdmin_CollectionController";
2007-08-18 13:38:11 +02:00
function Link() {
return 'admin/subsites/';
2007-08-18 13:38:11 +02:00
}
}
class SubsiteAdmin_CollectionController extends ModelAdmin_CollectionController {
function AddForm() {
$form = parent::AddForm();
$templates = DataObject::get('Subsite_Template', '', 'Title');
$templateArray = array('' => "(No template)");
2007-08-18 13:38:11 +02:00
if($templates) {
$templateArray = $templateArray + $templates->map('ID', 'Title');
2007-08-18 13:38:11 +02:00
}
$form->Fields()->addFieldsToTab('Root.Configuration', array(
new DropdownField('Type', 'Type', array(
'subsite' => 'New site',
'template' => 'New template',
)),
new DropdownField('TemplateID', 'Copy structure from:', $templateArray)
2007-08-18 13:38:11 +02:00
));
return $form;
2007-08-18 13:38:11 +02:00
}
function doCreate($data, $form, $request) {
if(isset($data['TemplateID']) && $data['TemplateID']) {
$template = DataObject::get_by_id('Subsite_Template', $data['TemplateID']);
} else {
$template = null;
}
// Create subsite from existing template
switch($data['Type']) {
case 'template':
if($template) $subsite = $template->duplicate();
else {
$subsite = new Subsite_Template();
$subsite->write();
}
break;
2010-03-01 03:48:45 +01:00
case 'subsite':
default:
if($template) $subsite = $template->createInstance($data['Title']);
else {
$subsite = new Subsite();
$subsite->Title = $data['Title'];
$subsite->write();
}
break;
}
2007-10-11 05:05:58 +02:00
$form->dataFieldByName('Domains')->setExtraData(array(
"SubsiteID" => $subsite->ID,
));
$form->saveInto($subsite);
$subsite->write();
if(Director::is_ajax()) {
$recordController = new ModelAdmin_RecordController($this, $request, $subsite->ID);
return new HTTPResponse(
$recordController->EditForm()->forAjaxTemplate(),
200,
sprintf(
_t('ModelAdmin.LOADEDFOREDITING', "Loaded '%s' for editing."),
$subsite->Title
)
);
} else {
Director::redirect(Controller::join_links($this->Link(), $subsitess->ID , 'edit'));
}
2007-10-11 05:05:58 +02:00
}
2007-08-18 13:38:11 +02:00
}
2007-08-18 13:38:11 +02:00
?>