1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\Forms\GridField; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Control\Controller; |
6
|
|
|
use SilverStripe\View\ArrayData; |
7
|
|
|
use SilverStripe\View\SSViewer; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* A button that allows a user to view readonly details of a record. This is |
11
|
|
|
* disabled by default and intended for use in readonly {@link GridField} |
12
|
|
|
* instances. |
13
|
|
|
*/ |
14
|
|
|
class GridFieldViewButton implements GridField_ColumnProvider, GridField_ActionMenuLink |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @inheritdoc |
18
|
|
|
*/ |
19
|
|
|
public function getTitle($gridField, $record, $columnName) |
20
|
|
|
{ |
21
|
|
|
return _t(__CLASS__ . '.VIEW', "View"); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @inheritdoc |
26
|
|
|
*/ |
27
|
|
|
public function getGroup($gridField, $record, $columnName) |
28
|
|
|
{ |
29
|
|
|
return GridField_ActionMenuItem::DEFAULT_GROUP; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @inheritdoc |
34
|
|
|
*/ |
35
|
|
|
public function getExtraData($gridField, $record, $columnName) |
36
|
|
|
{ |
37
|
|
|
return [ |
38
|
|
|
"classNames" => "font-icon-eye action-detail view-link" |
39
|
|
|
]; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @inheritdoc |
44
|
|
|
*/ |
45
|
|
|
public function getUrl($gridField, $record, $columnName) |
46
|
|
|
{ |
47
|
|
|
return Controller::join_links($gridField->Link('item'), $record->ID, 'view'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function augmentColumns($field, &$columns) |
51
|
|
|
{ |
52
|
|
|
if (!in_array('Actions', $columns)) { |
53
|
|
|
$columns[] = 'Actions'; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function getColumnsHandled($field) |
58
|
|
|
{ |
59
|
|
|
return ['Actions']; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function getColumnContent($field, $record, $col) |
63
|
|
|
{ |
64
|
|
|
if (!$record->canView()) { |
65
|
|
|
return null; |
66
|
|
|
} |
67
|
|
|
$data = new ArrayData([ |
68
|
|
|
'Link' => Controller::join_links($field->Link('item'), $record->ID, 'view') |
69
|
|
|
]); |
70
|
|
|
$template = SSViewer::get_templates_by_class($this, '', __CLASS__); |
71
|
|
|
return $data->renderWith($template); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function getColumnAttributes($field, $record, $col) |
75
|
|
|
{ |
76
|
|
|
return ['class' => 'grid-field__col-compact']; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function getColumnMetadata($gridField, $col) |
80
|
|
|
{ |
81
|
|
|
return ['title' => null]; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|