CMSPageHistoryViewerController::getEditForm()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 12
c 2
b 0
f 0
nc 2
nop 2
dl 0
loc 22
rs 9.8666
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
The private property $url_segment is not used, and could be removed.
Loading history...
24
25
    private static $url_rule = '/$Action/$ID/$VersionID/$OtherVersionID';
0 ignored issues
show
introduced by
The private property $url_rule is not used, and could be removed.
Loading history...
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
introduced by
The private property $url_priority is not used, and could be removed.
Loading history...
33
34
    private static $required_permission_codes = 'CMS_ACCESS_CMSMain';
0 ignored issues
show
introduced by
The private property $required_permission_codes is not used, and could be removed.
Loading history...
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
introduced by
$record is of type SilverStripe\CMS\Model\SiteTree, thus it always evaluated to true.
Loading history...
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