Completed
Pull Request — master (#185)
by Janne
02:32
created

CommentsGridFieldConfig::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 50
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 0 Features 0
Metric Value
c 6
b 0
f 0
dl 0
loc 50
rs 9.3333
cc 1
eloc 30
nc 1
nop 1
1
<?php
2
3
class CommentsGridFieldConfig extends GridFieldConfig_RecordEditor
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    public function __construct($itemsPerPage = 25)
6
    {
7
        parent::__construct($itemsPerPage);
8
9
        // $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...
10
11
        $this->addComponent(new CommentsGridFieldAction());
12
13
        // Format column
14
        $columns = $this->getComponentByType('GridFieldDataColumns');
15
        $columns->setFieldFormatting(array(
16
            'ParentTitle' => function ($value, &$item) {
17
                return sprintf(
18
                    '<a href="%s" class="cms-panel-link external-link action" target="_blank">%s</a>',
19
                    Convert::raw2att($item->Link()),
20
                    $item->obj('ParentTitle')->forTemplate()
21
                );
22
            }
23
        ));
24
25
        // Add bulk option
26
        $manager = new GridFieldBulkManager();
27
28
        $manager->addBulkAction(
29
            'spam', 
30
            _t('CommentsGridFieldConfig.SPAM', 'Spam'), 
31
            'CommentsGridFieldBulkAction_Handlers',
32
            array(
33
                'isAjax' => true,
34
                'icon' => 'cross',
35
                'isDestructive' => false
36
            )
37
        );
38
39
        $manager->addBulkAction(
40
            'approve', 
41
            _t('CommentsGridFieldConfig.APPROVE', 'Approve'), 
42
            'CommentsGridFieldBulkAction_Handlers',
43
            array(
44
                'isAjax' => true,
45
                'icon' => 'cross',
46
                'isDestructive' => false
47
            )
48
        );
49
50
        $manager->removeBulkAction('bulkEdit');
51
        $manager->removeBulkAction('unLink');
52
53
        $this->addComponent($manager);
54
    }
55
}
56