Completed
Push — master ( 6214aa...daa834 )
by Jason
08:16
created

PromoBlock::canView()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 8
cp 0
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 7
nc 4
nop 1
crap 30
1
<?php
2
3
class PromoBlock extends Block
4
{
5
    /**
6
     * @return string
7
     */
8 6
    public function singular_name()
9
    {
10 6
        return _t('PromoBlock.SINGULARNAME', 'Promo Block');
11
    }
12
13
    /**
14
     * @return string
15
     */
16
    public function plural_name()
17
    {
18
        return _t('PromoBlock.PLURALNAME', 'Promo Blocks');
19
    }
20
21
    /**
22
     * @var array
23
     */
24
    private static $many_many = array(
25
        'Promos' => 'PromoObject',
26
    );
27
28
    /**
29
     * @var array
30
     */
31
    private static $many_many_extraFields = array(
32
        'Promos' => array(
33
            'SortOrder' => 'Int',
34
        ),
35
    );
36
37
    /**
38
     * @return FieldList
39
     */
40 1
    public function getCMSFields()
41
    {
42 1
        $fields = parent::getCMSFields();
43
44 1
        if ($this->ID) {
45 1
            $config = GridFieldConfig_RelationEditor::create();
46 1
            if (class_exists('GridFieldSortableRows')) {
47
                $config->addComponent(new GridFieldSortableRows('SortOrder'));
48
            }
49 1
            if (class_exists('GridFieldAddExistingSearchButton')) {
50 1
                $config->removeComponentsByType('GridFieldAddExistingAutocompleter');
51 1
                $config->addComponent(new GridFieldAddExistingSearchButton());
52 1
            }
53 1
            $promos = $this->Promos()->sort('SortOrder');
0 ignored issues
show
Documentation Bug introduced by
The method Promos does not exist on object<PromoBlock>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
54 1
            $promoField = GridField::create('Promos', 'Promos', $promos, $config);
55
56 1
            $fields->addFieldsToTab('Root.Main', array(
57 1
                $promoField,
58 1
            ));
59 1
        }
60
61 1
        return $fields;
62
    }
63
64
    /**
65
     * @return mixed
66
     */
67 1
    public function getPromoList()
68
    {
69 1
        return $this->Promos()->sort('SortOrder');
0 ignored issues
show
Documentation Bug introduced by
The method Promos does not exist on object<PromoBlock>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
70
    }
71
}