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 0
if (!class_exists(CMSMain::class)) {
13 0
    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
    /**
28
     * {@inheritDoc}
29
     *
30
     * This is one higher than CMSPageHistoryController to give it priority
31
     */
32
    private static $url_priority = 43;
33

34
    private static $required_permission_codes = 'CMS_ACCESS_CMSMain';
35

36 1
    public function getEditForm($id = null, $fields = null)
37
    {
38
        /** @var DataObject $record */
39 1
        $record = $this->getRecord($id ?: $this->currentPageID());
40

41
        /** @var Form $form */
42 1
        $form = parent::getEditForm($id);
43 1
        $form->addExtraClass('history-viewer__form');
44
        // Disable default CMS preview
45 1
        $form->removeExtraClass('cms-previewable');
46

47 1
        if ($record) {
48 1
            $fieldList = FieldList::create(
49 1
                HiddenField::create('ID', null, $record->ID),
50 1
                HistoryViewerField::create('PageHistory')
51 1
                    ->addExtraClass('history-viewer--standalone')
52 1
                    ->setForm($form)
53
            );
54 1
            $form->setFields($fieldList);
55
        }
56

57 1
        return $form;
58
    }
59

60 0
    public function getTabIdentifier()
61
    {
62 0
        return 'history';
63
    }
64
}

Read our documentation on viewing source code .

Loading