Completed
Push — master ( 84256f...dfcf1e )
by Will
9s
created

HistoryListField   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 43
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSchemaStateDefaults() 0 13 3
A getRecord() 0 4 1
A setRecord() 0 5 1
1
<?php
2
3
4
namespace SilverStripe\AssetAdmin\Forms;
5
6
use SilverStripe\Forms\FormField;
7
use SilverStripe\ORM\DataObject;
8
use SilverStripe\ORM\Versioning\Versioned;
9
10
/**
11
 * History view for file editor form
12
 */
13
class HistoryListField extends FormField
14
{
15
    /**
16
     * @var DataObject
17
     */
18
    protected $record = null;
19
20
    protected $schemaComponent = 'HistoryList';
21
22
    protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_CUSTOM;
23
24
    public function getSchemaStateDefaults()
25
    {
26
        $state = parent::getSchemaStateDefaults();
27
        if ($record = $this->getRecord()) {
28
            $latest = Versioned::get_latest_version($record->baseClass(), $record->ID);
29
            if ($latest) {
30
                $state['data']['fileId'] = $latest->ID;
31
                $state['data']['latestVersionId'] = $latest->Version;
32
            }
33
        }
34
35
        return $state;
36
    }
37
38
    /**
39
     * @return DataObject
40
     */
41
    public function getRecord()
42
    {
43
        return $this->record;
44
    }
45
46
    /**
47
     * @param DataObject $record
48
     * @return $this
49
     */
50
    public function setRecord(DataObject $record)
51
    {
52
        $this->record = $record;
53
        return $this;
54
    }
55
}
56