1 | <?php |
||
2 | |||
3 | namespace SilverStripe\Comments\Admin; |
||
4 | |||
5 | use SilverStripe\Comments\Model\Comment; |
||
6 | use SilverStripe\Control\Controller; |
||
7 | use SilverStripe\Forms\GridField\GridField; |
||
8 | use SilverStripe\Forms\GridField\GridField_ActionMenuItem; |
||
9 | use SilverStripe\Forms\GridField\GridField_ActionProvider; |
||
10 | use SilverStripe\Forms\GridField\GridField_ColumnProvider; |
||
11 | use SilverStripe\Forms\GridField\GridField_FormAction; |
||
12 | |||
13 | class CommentsGridFieldApproveAction implements |
||
14 | GridField_ColumnProvider, |
||
15 | GridField_ActionProvider, |
||
16 | GridField_ActionMenuItem |
||
17 | { |
||
18 | /** |
||
19 | * {@inheritdoc} |
||
20 | */ |
||
21 | public function augmentColumns($gridField, &$columns) |
||
22 | { |
||
23 | if (!in_array('Actions', $columns)) { |
||
24 | $columns[] = 'Actions'; |
||
25 | } |
||
26 | } |
||
27 | |||
28 | public function getTitle($gridField, $record, $columnName) |
||
29 | { |
||
30 | return _t(__CLASS__ . '.APPROVE', 'Approve'); |
||
31 | } |
||
32 | |||
33 | public function getExtraData($gridField, $record, $columnName) |
||
34 | { |
||
35 | |||
36 | $field = $this->getApproveAction($gridField, $record, $columnName); |
||
37 | |||
38 | if ($field) { |
||
39 | return $field->getAttributes(); |
||
40 | } |
||
41 | |||
42 | return null; |
||
43 | } |
||
44 | public function getGroup($gridField, $record, $columnName) |
||
45 | { |
||
46 | $field = $this->getApproveAction($gridField, $record, $columnName); |
||
47 | |||
48 | return $field ? GridField_ActionMenuItem::DEFAULT_GROUP: null; |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | */ |
||
54 | public function getColumnAttributes($gridField, $record, $columnName) |
||
55 | { |
||
56 | return ['class' => 'col-buttons grid-field__col-compact']; |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * {@inheritdoc} |
||
61 | */ |
||
62 | public function getColumnMetadata($gridField, $columnName) |
||
63 | { |
||
64 | if ($columnName === 'Actions') { |
||
65 | return ['title' => '']; |
||
66 | } |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * {@inheritdoc} |
||
71 | */ |
||
72 | public function getColumnsHandled($gridField) |
||
73 | { |
||
74 | return ['Actions']; |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * {@inheritdoc} |
||
79 | */ |
||
80 | public function getColumnContent($gridField, $record, $columnName) |
||
81 | { |
||
82 | if (!$record->canEdit()) { |
||
83 | return; |
||
84 | } |
||
85 | |||
86 | $field = $this->getApproveAction($gridField, $record, $columnName); |
||
87 | |||
88 | return $field ? $field->Field() : null; |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * Returns the FormAction object, used by other methods to get properties |
||
93 | * |
||
94 | * @return GridField_FormAction|null |
||
95 | */ |
||
96 | public function getApproveAction($gridField, $record, $columnName) |
||
0 ignored issues
–
show
|
|||
97 | { |
||
98 | $field = GridField_FormAction::create( |
||
99 | $gridField, |
||
100 | 'CustomAction' . $record->ID . 'Approve', |
||
101 | _t(__CLASS__ . '.APPROVE', 'Approve'), |
||
102 | 'approve', |
||
103 | ['RecordID' => $record->ID] |
||
104 | ) |
||
105 | ->addExtraClass(implode(' ', [ |
||
106 | 'btn', |
||
107 | 'btn-secondary', |
||
108 | 'grid-field__icon-action', |
||
109 | 'action-menu--handled', |
||
110 | 'font-icon-check-mark', |
||
111 | ])) |
||
112 | ->setAttribute('classNames', 'font-icon-check-mark'); |
||
113 | |||
114 | return ($record->IsSpam || !$record->Moderated) ? $field : null; |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * {@inheritdoc} |
||
119 | */ |
||
120 | public function getActions($gridField) |
||
121 | { |
||
122 | return ['approve']; |
||
123 | } |
||
124 | |||
125 | /** |
||
126 | * {@inheritdoc} |
||
127 | */ |
||
128 | public function handleAction(GridField $gridField, $actionName, $arguments, $data) |
||
129 | { |
||
130 | /** @var Comment $comment */ |
||
131 | $comment = Comment::get()->byID($arguments['RecordID']); |
||
132 | $comment->markApproved(); |
||
133 | |||
134 | // output a success message to the user |
||
135 | Controller::curr()->getResponse()->setStatusCode( |
||
136 | 200, |
||
137 | _t(__CLASS__ . '.COMMENTAPPROVED', 'Comment approved.') |
||
138 | ); |
||
139 | } |
||
140 | } |
||
141 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.