1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\Subsites\Forms; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Forms\DropdownField; |
6
|
|
|
use SilverStripe\Forms\Form; |
7
|
|
|
use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest; |
8
|
|
|
use SilverStripe\Subsites\Model\Subsite; |
9
|
|
|
|
10
|
|
|
class GridFieldSubsiteDetailFormItemRequest extends GridFieldDetailForm_ItemRequest |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
private static $allowed_actions = [ |
|
|
|
|
14
|
|
|
'ItemEditForm', |
15
|
|
|
]; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Builds an item edit form. The arguments to getCMSFields() are the popupController and |
19
|
|
|
* popupFormName, however this is an experimental API and may change. |
20
|
|
|
* |
21
|
|
|
* @todo In the future, we will probably need to come up with a tigher object representing a partially |
22
|
|
|
* complete controller with gaps for extra functionality. This, for example, would be a better way |
23
|
|
|
* of letting Security/login put its log-in form inside a UI specified elsewhere. |
24
|
|
|
* |
25
|
|
|
* @return Form |
26
|
|
|
* @see GridFieldDetailForm_ItemRequest::ItemEditForm() |
27
|
|
|
*/ |
28
|
|
|
public function ItemEditForm() |
29
|
|
|
{ |
30
|
|
|
$form = parent::ItemEditForm(); |
31
|
|
|
|
32
|
|
|
if ($this->record->ID == 0) { |
33
|
|
|
$templates = Subsite::get()->sort('Title'); |
34
|
|
|
$templateArray = []; |
35
|
|
|
if ($templates) { |
|
|
|
|
36
|
|
|
$templateArray = $templates->map('ID', 'Title'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$templateDropdown = new DropdownField( |
40
|
|
|
'TemplateID', |
41
|
|
|
_t('Subsite.COPYSTRUCTURE', 'Copy structure from:'), |
42
|
|
|
$templateArray |
43
|
|
|
); |
44
|
|
|
$templateDropdown->setEmptyString('(' . _t('Subsite.NOTEMPLATE', 'No template') . ')'); |
45
|
|
|
$form->Fields()->addFieldToTab('Root.Main', $templateDropdown); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return $form; |
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function doSave($data, $form) |
52
|
|
|
{ |
53
|
|
|
$new_record = $this->record->ID == 0; |
54
|
|
|
if ($new_record && isset($data['TemplateID']) && !empty($data['TemplateID'])) { |
55
|
|
|
$template = Subsite::get()->byID(intval($data['TemplateID'])); |
56
|
|
|
if ($template) { |
|
|
|
|
57
|
|
|
$this->record = $template->duplicate(); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return parent::doSave($data, $form); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|