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
|
|
|
/** |
20
|
|
|
* Unique context key used to differentiate the different use cases for HistoryViewer |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $contextKey; |
25
|
|
|
|
26
|
|
|
public function __construct($name, $title = null, $value = null) |
27
|
|
|
{ |
28
|
|
|
Requirements::javascript('silverstripe/versioned-admin:client/dist/js/bundle.js'); |
29
|
|
|
Requirements::css('silverstripe/versioned-admin:client/dist/styles/bundle.css'); |
30
|
|
|
|
31
|
|
|
parent::__construct($name, $title, $value); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Get the source record to view history for |
36
|
|
|
* |
37
|
|
|
* @return DataObject|null |
38
|
|
|
*/ |
39
|
|
|
public function getSourceRecord() |
40
|
|
|
{ |
41
|
|
|
return $this->getForm() ? $this->getForm()->getRecord() : null; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Get whether the record is previewable |
46
|
|
|
* |
47
|
|
|
* @return boolean |
48
|
|
|
*/ |
49
|
|
|
public function getPreviewEnabled() |
50
|
|
|
{ |
51
|
|
|
$record = $this->getSourceRecord(); |
52
|
|
|
|
53
|
|
|
return $record && $record instanceof CMSPreviewable; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getContextKey() |
57
|
|
|
{ |
58
|
|
|
if ($this->contextKey) { |
59
|
|
|
return $this->contextKey; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
// Default to using the DataObject's DB table name as the unique identifier |
63
|
|
|
return DataObject::getSchema()->baseDataTable(get_class($this->getSourceRecord())); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function setContextKey($contextKey) |
67
|
|
|
{ |
68
|
|
|
$this->contextKey = (string) $contextKey; |
69
|
|
|
return $this; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|