1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
namespace SilverStripe\VersionedAdmin\Controllers; |
4
|
|
|
|
5
|
|
|
use SilverStripe\CMS\Controllers\CMSMain; |
6
|
|
|
use SilverStripe\Forms\FieldList; |
7
|
|
|
use SilverStripe\Forms\Form; |
8
|
|
|
use SilverStripe\Forms\HiddenField; |
9
|
|
|
use SilverStripe\ORM\DataObject; |
10
|
|
|
use SilverStripe\VersionedAdmin\Forms\HistoryViewerField; |
11
|
|
|
|
12
|
|
|
if (!class_exists(CMSMain::class)) { |
13
|
|
|
return; |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* The history viewer controller replaces the {@link CMSPageHistoryController} and uses the React based |
18
|
|
|
* {@link HistoryViewerField} to display the history for a {@link DataObject} that has the {@link Versioned} |
19
|
|
|
* extension. |
20
|
|
|
*/ |
21
|
|
|
class CMSPageHistoryViewerController extends CMSMain |
22
|
|
|
{ |
23
|
|
|
private static $url_segment = 'pages/history'; |
|
|
|
|
24
|
|
|
|
25
|
|
|
private static $url_rule = '/$Action/$ID/$VersionID/$OtherVersionID'; |
|
|
|
|
26
|
|
|
|
27
|
|
|
private static $url_priority = 42; |
|
|
|
|
28
|
|
|
|
29
|
|
|
private static $required_permission_codes = 'CMS_ACCESS_CMSMain'; |
|
|
|
|
30
|
|
|
|
31
|
|
|
public function getEditForm($id = null, $fields = null) |
32
|
|
|
{ |
33
|
|
|
/** @var DataObject $record */ |
34
|
|
|
$record = $this->getRecord($id ?: $this->currentPageID()); |
35
|
|
|
|
36
|
|
|
/** @var Form $form */ |
37
|
|
|
$form = parent::getEditForm($id); |
38
|
|
|
$form->addExtraClass('history-viewer__form'); |
39
|
|
|
|
40
|
|
|
if ($record) { |
|
|
|
|
41
|
|
|
$fieldList = FieldList::create( |
42
|
|
|
HiddenField::create('ID', null, $record->ID), |
43
|
|
|
HistoryViewerField::create('PageHistory') |
44
|
|
|
->setForm($form) |
45
|
|
|
); |
46
|
|
|
$form->setFields($fieldList); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return $form; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getTabIdentifier() |
53
|
|
|
{ |
54
|
|
|
return 'history'; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.