Passed
Push — master ( 84ec48...65ffa5 )
by Robbie
03:15
created

HistoryViewerField::getPreviewEnabled()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\VersionedAdmin\Forms;
4
5
use SilverStripe\Forms\FormField;
6
use SilverStripe\ORM\CMSPreviewable;
7
use SilverStripe\ORM\DataObject;
8
use SilverStripe\View\Requirements;
9
10
class HistoryViewerField extends FormField
11
{
12
    /**
13
     * Default to using the SiteTree component
14
     *
15
     * @var string
16
     */
17
    protected $schemaComponent = 'PageHistoryViewer';
18
19
    public function __construct($name, $title = null, $value = null)
20
    {
21
        Requirements::javascript('silverstripe/versioned-admin:client/dist/js/bundle.js');
22
        Requirements::css('silverstripe/versioned-admin:client/dist/styles/bundle.css');
23
24
        parent::__construct($name, $title, $value);
25
    }
26
27
    /**
28
     * Get the source record to view history for
29
     *
30
     * @return DataObject|null
31
     */
32
    public function getSourceRecord()
33
    {
34
        return $this->getForm() ? $this->getForm()->getRecord() : null;
35
    }
36
37
    /**
38
     * Get whether the record is previewable
39
     *
40
     * @return boolean
41
     */
42
    public function getPreviewEnabled()
43
    {
44
        $record = $this->getSourceRecord();
45
46
        return $record && $record instanceof CMSPreviewable;
47
    }
48
}
49