Passed
Push — master ( 161f5f...780ea2 )
by Robbie
02:43 queued 10s
created

src/Admin/CommentsGridFieldConfig.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace SilverStripe\Comments\Admin;
4
5
use Colymba\BulkManager\BulkManager;
6
use SilverStripe\Comments\Admin\CommentsGridFieldBulkAction\ApproveHandler;
7
use SilverStripe\Comments\Admin\CommentsGridFieldBulkAction\SpamHandler;
8
use SilverStripe\Core\Convert;
9
use SilverStripe\Forms\GridField\GridField_ActionMenu;
10
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
11
use SilverStripe\Forms\GridField\GridFieldDataColumns;
12
13
class CommentsGridFieldConfig extends GridFieldConfig_RecordEditor
14
{
15
    public function __construct($itemsPerPage = 25)
16
    {
17
        parent::__construct($itemsPerPage);
18
19
        // $this->addComponent(new GridFieldExportButton());
20
21
        $this->addComponents([
22
            new CommentsGridFieldSpamAction(),
23
            new CommentsGridFieldApproveAction(),
24
        ]);
25
26
        // Format column
27
        /** @var GridFieldDataColumns $columns */
28
        $columns = $this->getComponentByType(GridFieldDataColumns::class);
29
        $columns->setFieldFormatting([
30
            'ParentTitle' => function ($value, &$item) {
31
                return sprintf(
32
                    '<a href="%s" class="cms-panel-link external-link action" target="_blank">%s</a>',
33
                    Convert::raw2att($item->Link()),
0 ignored issues
show
It seems like SilverStripe\Core\Convert::raw2att($item->Link()) can also be of type array and array; however, parameter $args of sprintf() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
                    /** @scrutinizer ignore-type */ Convert::raw2att($item->Link()),
Loading history...
34
                    $item->obj('ParentTitle')->forTemplate()
35
                );
36
            }
37
        ]);
38
39
        // Add bulk option
40
        $manager = BulkManager::create(null, false);
41
42
        $spamAction = SpamHandler::create()->setLabel(_t(__CLASS__ . '.SPAM', 'Spam'));
43
        $approveAction = ApproveHandler::create()->setLabel(_t(__CLASS__ . '.APPROVE', 'Approve'));
44
45
        $manager
46
            ->addBulkAction($spamAction)
47
            ->addBulkAction($approveAction);
48
49
        $this->addComponent($manager);
50
    }
51
}
52