silverstripe-subsites/code/SubsiteAdmin.php

70 lines
1.9 KiB
PHP
Raw Normal View History

2007-08-18 11:38:11 +00:00
<?php
/**
* Admin interface to manage and create {@link Subsite} instances.
*
* @package subsites
*/
class SubsiteAdmin extends ModelAdmin {
2007-08-18 11:38:11 +00:00
static $managed_models = array('Subsite');
static $url_segment = 'subsites';
static $menu_title = "Subsites";
static $collection_controller_class = "SubsiteAdmin_CollectionController";
}
class SubsiteAdmin_CollectionController extends ModelAdmin_CollectionController {
function AddForm() {
$form = parent::AddForm();
$subsites = DataObject::get('Subsite', '', 'Title');
$subsiteMap = array('' => "(No template)", -1 => '(Main Site)');
if($subsites) {
$subsiteMap = $subsiteMap + $subsites->map('ID', 'Title');
2007-08-18 11:38:11 +00:00
}
$form->Fields()->addFieldsToTab('Root.Configuration', array(
new DropdownField('TemplateID', 'Copy structure from:', $subsiteMap)
2007-08-18 11:38:11 +00:00
));
return $form;
2007-08-18 11:38:11 +00:00
}
function doCreate($data, $form, $request) {
if(isset($data['TemplateID']) && $data['TemplateID'] == -1) {
// Copy from main site. Hacky as it relies on ID=0
// in order to query the main site (which is technically not contained in a Subsite record)
$mainsite = new Subsite();
$subsite = $mainsite->duplicate();
} elseif(isset($data['TemplateID']) && $data['TemplateID']) {
$template = DataObject::get_by_id('Subsite', $data['TemplateID']);
$subsite = $template->duplicate();
} else {
$subsite = new Subsite();
}
2007-10-11 03:05:58 +00: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);
2010-03-04 22:52:16 +00:00
return new SS_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 03:05:58 +00:00
}
2007-08-18 11:38:11 +00:00
}
2007-08-18 11:38:11 +00:00
?>