2017-04-23 22:23:34 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\Subsites\Forms;
|
|
|
|
|
|
|
|
use SilverStripe\Forms\DropdownField;
|
|
|
|
use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest;
|
|
|
|
use SilverStripe\Subsites\Model\Subsite;
|
|
|
|
|
|
|
|
class GridFieldSubsiteDetailForm_ItemRequest extends GridFieldDetailForm_ItemRequest
|
|
|
|
{
|
|
|
|
|
2017-06-01 15:57:53 +02:00
|
|
|
private static $allowed_actions = [
|
2017-04-23 22:23:34 +02:00
|
|
|
'ItemEditForm',
|
2017-06-01 15:57:53 +02:00
|
|
|
];
|
2017-04-23 22:23:34 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds an item edit form. The arguments to getCMSFields() are the popupController and
|
|
|
|
* popupFormName, however this is an experimental API and may change.
|
|
|
|
*
|
|
|
|
* @todo In the future, we will probably need to come up with a tigher object representing a partially
|
|
|
|
* complete controller with gaps for extra functionality. This, for example, would be a better way
|
|
|
|
* of letting Security/login put its log-in form inside a UI specified elsewhere.
|
|
|
|
*
|
|
|
|
* @return Form
|
|
|
|
* @see GridFieldDetailForm_ItemRequest::ItemEditForm()
|
|
|
|
*/
|
|
|
|
public function ItemEditForm()
|
|
|
|
{
|
2017-06-01 15:57:53 +02:00
|
|
|
$form = parent::ItemEditForm();
|
2017-04-23 22:23:34 +02:00
|
|
|
|
|
|
|
if ($this->record->ID == 0) {
|
|
|
|
$templates = Subsite::get()->sort('Title');
|
2017-06-01 15:57:53 +02:00
|
|
|
$templateArray = [];
|
2017-04-23 22:23:34 +02:00
|
|
|
if ($templates) {
|
|
|
|
$templateArray = $templates->map('ID', 'Title');
|
|
|
|
}
|
|
|
|
|
2017-06-01 15:57:53 +02:00
|
|
|
$templateDropdown = new DropdownField('TemplateID', _t('Subsite.COPYSTRUCTURE', 'Copy structure from:'),
|
|
|
|
$templateArray);
|
2017-04-23 22:23:34 +02:00
|
|
|
$templateDropdown->setEmptyString('(' . _t('Subsite.NOTEMPLATE', 'No template') . ')');
|
|
|
|
$form->Fields()->addFieldToTab('Root.Configuration', $templateDropdown);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $form;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function doSave($data, $form)
|
|
|
|
{
|
|
|
|
$new_record = $this->record->ID == 0;
|
|
|
|
if ($new_record && isset($data['TemplateID']) && !empty($data['TemplateID'])) {
|
|
|
|
$template = Subsite::get()->byID(intval($data['TemplateID']));
|
|
|
|
if ($template) {
|
|
|
|
$this->record = $template->duplicate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::doSave($data, $form);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|