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 CommentsGridFieldSpamAction 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__ . '.SPAM', 'Spam'); |
||
31 | } |
||
32 | |||
33 | public function getExtraData($gridField, $record, $columnName) |
||
34 | { |
||
35 | |||
36 | $field = $this->getSpamAction($gridField, $record, $columnName); |
||
37 | |||
38 | if ($field) { |
||
39 | return $field->getAttributes(); |
||
40 | } |
||
41 | |||
42 | return null; |
||
43 | } |
||
44 | |||
45 | public function getGroup($gridField, $record, $columnName) |
||
46 | { |
||
47 | $field = $this->getSpamAction($gridField, $record, $columnName); |
||
48 | |||
49 | return $field ? GridField_ActionMenuItem::DEFAULT_GROUP: null; |
||
50 | } |
||
51 | |||
52 | |||
53 | /** |
||
54 | * {@inheritdoc} |
||
55 | */ |
||
56 | public function getColumnAttributes($gridField, $record, $columnName) |
||
57 | { |
||
58 | return ['class' => 'col-buttons grid-field__col-compact']; |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * {@inheritdoc} |
||
63 | */ |
||
64 | public function getColumnMetadata($gridField, $columnName) |
||
65 | { |
||
66 | if ($columnName === 'Actions') { |
||
67 | return ['title' => '']; |
||
68 | } |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | */ |
||
74 | public function getColumnsHandled($gridField) |
||
75 | { |
||
76 | return ['Actions']; |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * {@inheritdoc} |
||
81 | */ |
||
82 | public function getColumnContent($gridField, $record, $columnName) |
||
83 | { |
||
84 | if (!$record->canEdit()) { |
||
85 | return; |
||
86 | } |
||
87 | |||
88 | $field = $this->getSpamAction($gridField, $record, $columnName); |
||
89 | |||
90 | return $field ? $field->Field() : null; |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * Returns the FormAction object, used by other methods to get properties |
||
95 | * |
||
96 | * @return GridField_FormAction|null |
||
97 | */ |
||
98 | public function getSpamAction($gridField, $record, $columnName) |
||
0 ignored issues
–
show
|
|||
99 | { |
||
100 | $field = GridField_FormAction::create( |
||
101 | $gridField, |
||
102 | 'CustomAction' . $record->ID . 'Spam', |
||
103 | _t(__CLASS__ . '.SPAM', 'Spam'), |
||
104 | 'spam', |
||
105 | ['RecordID' => $record->ID] |
||
106 | ) |
||
107 | ->addExtraClass(implode(' ', [ |
||
108 | 'btn', |
||
109 | 'btn-secondary', |
||
110 | 'grid-field__icon-action', |
||
111 | 'action-menu--handled', |
||
112 | 'font-icon-cross-mark', |
||
113 | ])) |
||
114 | ->setAttribute('classNames', 'font-icon-cross-mark'); |
||
115 | return (!$record->IsSpam || !$record->Moderated) ? $field : null; |
||
116 | } |
||
117 | |||
118 | /** |
||
119 | * {@inheritdoc} |
||
120 | */ |
||
121 | public function getActions($gridField) |
||
122 | { |
||
123 | return ['spam']; |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * {@inheritdoc} |
||
128 | */ |
||
129 | public function handleAction(GridField $gridField, $actionName, $arguments, $data) |
||
130 | { |
||
131 | /** @var Comment $comment */ |
||
132 | $comment = Comment::get()->byID($arguments['RecordID']); |
||
133 | $comment->markSpam(); |
||
134 | |||
135 | // output a success message to the user |
||
136 | Controller::curr()->getResponse()->setStatusCode( |
||
137 | 200, |
||
138 | _t(__CLASS__ . '.COMMENTMARKEDSPAM', 'Comment marked as spam.') |
||
139 | ); |
||
140 | } |
||
141 | } |
||
142 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.