These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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( |
||
0 ignored issues
–
show
|
|||
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( |
||
0 ignored issues
–
show
array('date' => $record-...('LastEdited')->Nice()) is of type array<string,?,{"date":"?"}> , but the function expects a string .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
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 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: