Completed
Push — master ( 9dab44...8bd79e )
by Robbie
02:00
created

CommentsGridFieldConfig   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 6
dl 0
loc 35
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 32 1
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\GridFieldConfig_RecordEditor;
10
use SilverStripe\Forms\GridField\GridFieldDataColumns;
11
12
class CommentsGridFieldConfig extends GridFieldConfig_RecordEditor
13
{
14
    public function __construct($itemsPerPage = 25)
15
    {
16
        parent::__construct($itemsPerPage);
17
18
        // $this->addComponent(new GridFieldExportButton());
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
19
20
        $this->addComponent(new CommentsGridFieldAction());
21
22
        // Format column
23
        $columns = $this->getComponentByType(GridFieldDataColumns::class);
24
        $columns->setFieldFormatting(array(
25
            'ParentTitle' => function ($value, &$item) {
26
                return sprintf(
27
                    '<a href="%s" class="cms-panel-link external-link action" target="_blank">%s</a>',
28
                    Convert::raw2att($item->Link()),
29
                    $item->obj('ParentTitle')->forTemplate()
30
                );
31
            }
32
        ));
33
34
        // Add bulk option
35
        $manager = new BulkManager(null, false);
36
37
        $spamAction = SpamHandler::create()->setLabel(_t(__CLASS__ . '.SPAM', 'Spam'));
38
        $approveAction = ApproveHandler::create()->setLabel(_t(__CLASS__ . '.APPROVE', 'Approve'));
39
40
        $manager
41
            ->addBulkAction($spamAction)
42
            ->addBulkAction($approveAction);
43
44
        $this->addComponent($manager);
45
    }
46
}
47