1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use SaltedHerring\Debugger as Debugger; |
4
|
|
|
|
5
|
|
|
class VersionedForm extends GridFieldDetailForm { |
6
|
|
|
|
7
|
|
|
} |
8
|
|
|
|
9
|
|
|
class VersionedForm_ItemRequest extends GridFieldDetailForm_ItemRequest { |
10
|
|
|
private static $allowed_actions = array( |
|
|
|
|
11
|
|
|
'edit', |
12
|
|
|
'view', |
13
|
|
|
'ItemEditForm', |
14
|
|
|
'doPublish', |
15
|
|
|
'doUnpublish' |
16
|
|
|
); |
17
|
|
|
|
18
|
|
|
public function ItemEditForm() { |
19
|
|
|
$form = parent::ItemEditForm(); |
20
|
|
|
if ($form instanceof Form) { |
21
|
|
|
$actions = $form->Actions(); |
22
|
|
|
$record = $this->record; |
23
|
|
|
$actions->insertBefore('action_doDelete', $btnPublish = FormAction::create('doPublish','Save & Publish')); |
24
|
|
|
$btnPublish->addExtraClass('ss-ui-action-constructive'); |
25
|
|
|
if (!empty($record->ID)) { |
26
|
|
|
if ($record->isPublished()) { |
27
|
|
|
$actions->removeByName('action_doDelete'); |
28
|
|
|
$actions->push(FormAction::create('doUnpublish', 'Unpublish')->addExtraClass('ss-ui-action-destructive')); |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
$form->setActions($actions); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
return $form; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function doUnpublish($data, $form) { |
|
|
|
|
38
|
|
|
$this->record->deleteFromStage('Live'); |
39
|
|
|
$controller = Controller::curr(); |
40
|
|
|
$form->sessionMessage('Block unpublished', 'good', false); |
41
|
|
|
return $this->edit($controller->getRequest()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function doPublish($data, $form) { |
|
|
|
|
45
|
|
|
$form->saveInto($this->record); |
46
|
|
|
$this->record->write(); |
47
|
|
|
$this->record->byPass = true; |
48
|
|
|
$this->record->doPublish(); |
49
|
|
|
$form->sessionMessage('Block published', 'good', false); |
50
|
|
|
$controller = Controller::curr(); |
51
|
|
|
return $this->edit($controller->getRequest()); |
52
|
|
|
} |
53
|
|
|
} |
This check marks private properties in classes that are never used. Those properties can be removed.