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'; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
24 | |||
25 | private static $url_rule = '/$Action/$ID/$VersionID/$OtherVersionID'; |
||
0 ignored issues
–
show
|
|||
26 | |||
27 | /** |
||
28 | * {@inheritDoc} |
||
29 | * |
||
30 | * This is one higher than CMSPageHistoryController to give it priority |
||
31 | */ |
||
32 | private static $url_priority = 43; |
||
0 ignored issues
–
show
|
|||
33 | |||
34 | private static $required_permission_codes = 'CMS_ACCESS_CMSMain'; |
||
0 ignored issues
–
show
|
|||
35 | |||
36 | public function getEditForm($id = null, $fields = null) |
||
37 | { |
||
38 | /** @var DataObject $record */ |
||
39 | $record = $this->getRecord($id ?: $this->currentPageID()); |
||
40 | |||
41 | /** @var Form $form */ |
||
42 | $form = parent::getEditForm($id); |
||
43 | $form->addExtraClass('history-viewer__form'); |
||
44 | // Disable default CMS preview |
||
45 | $form->removeExtraClass('cms-previewable'); |
||
46 | |||
47 | if ($record) { |
||
0 ignored issues
–
show
|
|||
48 | $fieldList = FieldList::create( |
||
49 | HiddenField::create('ID', null, $record->ID), |
||
50 | HistoryViewerField::create('PageHistory') |
||
51 | ->addExtraClass('history-viewer--standalone') |
||
52 | ->setForm($form) |
||
53 | ); |
||
54 | $form->setFields($fieldList); |
||
55 | } |
||
56 | |||
57 | return $form; |
||
58 | } |
||
59 | |||
60 | public function getTabIdentifier() |
||
61 | { |
||
62 | return 'history'; |
||
63 | } |
||
64 | } |
||
65 |