1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Provides a component to the {@link GridField} which shows the publish status of a page. |
5
|
|
|
* |
6
|
|
|
* @package silverstripe |
7
|
|
|
* @subpackage lumberjack |
8
|
|
|
* |
9
|
|
|
* @author Michael Strong <[email protected]> |
10
|
|
|
**/ |
11
|
|
|
class GridFieldSiteTreeState implements GridField_ColumnProvider |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
public function augmentColumns($gridField, &$columns) |
15
|
|
|
{ |
16
|
|
|
// Ensure Actions always appears as the last column. |
17
|
|
|
$key = array_search("Actions", $columns); |
18
|
|
|
if ($key !== false) { |
19
|
|
|
unset($columns[$key]); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
$columns = array_merge($columns, array( |
23
|
|
|
"State", |
24
|
|
|
"Actions", |
25
|
|
|
)); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function getColumnsHandled($gridField) |
29
|
|
|
{ |
30
|
|
|
return array("State"); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function getColumnContent($gridField, $record, $columnName) |
34
|
|
|
{ |
35
|
|
|
if ($columnName == "State") { |
36
|
|
|
if ($record->hasMethod("isPublished")) { |
37
|
|
|
$modifiedLabel = ""; |
38
|
|
|
if ($record->isModifiedOnStage) { |
39
|
|
|
$modifiedLabel = "<span class='modified'>" . _t("GridFieldSiteTreeState.Modified", "Modified") . "</span>"; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$published = $record->isPublished(); |
43
|
|
|
if (!$published) { |
44
|
|
|
return _t( |
45
|
|
|
"GridFieldSiteTreeState.Draft", |
46
|
|
|
'<i class="btn-icon gridfield-icon btn-icon-pencil"></i> Saved as Draft on {date}', |
47
|
|
|
"State for when a post is saved.", |
48
|
|
|
array( |
|
|
|
|
49
|
|
|
"date" => $record->dbObject("LastEdited")->Nice() |
50
|
|
|
) |
51
|
|
|
); |
52
|
|
|
} else { |
53
|
|
|
return _t( |
54
|
|
|
"GridFieldSiteTreeState.Published", |
55
|
|
|
'<i class="btn-icon gridfield-icon btn-icon-accept"></i> Published on {date}', |
56
|
|
|
"State for when a post is published.", |
57
|
|
|
array( |
|
|
|
|
58
|
|
|
"date" => $record->dbObject("LastEdited")->Nice() |
59
|
|
|
) |
60
|
|
|
) . $modifiedLabel; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function getColumnAttributes($gridField, $record, $columnName) |
67
|
|
|
{ |
68
|
|
|
if ($columnName == "State") { |
69
|
|
|
if ($record->hasMethod("isPublished")) { |
70
|
|
|
$published = $record->isPublished(); |
71
|
|
|
if (!$published) { |
72
|
|
|
$class = "gridfield-icon draft"; |
73
|
|
|
} else { |
74
|
|
|
$class = "gridfield-icon published"; |
75
|
|
|
} |
76
|
|
|
return array("class" => $class); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
return array(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function getColumnMetaData($gridField, $columnName) |
83
|
|
|
{ |
84
|
|
|
switch ($columnName) { |
85
|
|
|
case 'State': |
86
|
|
|
return array("title" => _t("GridFieldSiteTreeState.StateTitle", "State", "Column title for state")); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.