BlockButtonField::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 44
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 28
c 1
b 0
f 0
nc 4
nop 3
dl 0
loc 44
rs 9.472
1
<?php
2
3
namespace LeKoala\Blocks\Fields;
4
5
use SilverStripe\Forms\TextField;
6
use SilverStripe\Forms\FieldList;
7
use SilverStripe\Forms\CheckboxField;
8
use SilverStripe\Forms\CompositeField;
9
use SilverStripe\Forms\FieldGroup;
10
11
class BlockButtonField extends CompositeField
12
{
13
    public function __construct($name, $title = null, $value = null)
14
    {
15
        $children = new FieldList();
16
17
        $TitleField = TextField::create(
18
            "{$name}[Title]",
19
            'Title'
20
        );
21
        $children->push($TitleField);
22
23
        $LinkField = TextField::create(
24
            "{$name}[Link]",
25
            'Link'
26
        );
27
        $children->push($LinkField);
28
29
        $group = FieldGroup::create();
30
        $children->push($group);
31
32
        $NewWindowField = CheckboxField::create(
33
            "{$name}[NewWindow]",
34
            'Open in new window?'
35
        );
36
        $group->push($NewWindowField);
37
38
        $ExtraClassesField = TextField::create(
39
            "{$name}[ExtraClasses]",
40
            ''
41
        );
42
        $ExtraClassesField->setAttribute('placeholder', 'Extra Classes');
43
        $group->push($ExtraClassesField);
44
45
        parent::__construct($children);
46
47
        $this->setName($name);
48
49
        if ($title === null) {
50
            $this->title = self::name_to_label($name);
51
        } else {
52
            $this->title = $title;
53
        }
54
55
        if ($value !== null) {
56
            $this->setValue($value);
57
        }
58
    }
59
60
    public function setValue($value, $data = null)
61
    {
62
        if (is_array($value)) {
63
            if (isset($value['Title'])) {
64
                $this->getTitleField()->setValue($value['Title']);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->getTitleField() targeting LeKoala\Blocks\Fields\Bl...nField::getTitleField() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
65
            }
66
            if (isset($value['Link'])) {
67
                $this->getLinkField()->setValue($value['Link']);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->getLinkField() targeting LeKoala\Blocks\Fields\Bl...onField::getLinkField() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
68
            }
69
            if (isset($value['NewWindow'])) {
70
                $this->getNewWindowField()->setValue($value['NewWindow']);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->getNewWindowField() targeting LeKoala\Blocks\Fields\Bl...ld::getNewWindowField() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
71
            }
72
            if (isset($value['ExtraClasses'])) {
73
                $this->getExtraClassesField()->setValue($value['ExtraClasses']);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->getExtraClassesField() targeting LeKoala\Blocks\Fields\Bl...:getExtraClassesField() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
74
            }
75
        }
76
        return parent::setValue($value, $data);
77
    }
78
79
    public function getTitleField()
80
    {
81
        $name = $this->name;
82
        return $this->fieldByName("{$name}[Title]");
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->fieldByName($name.'[Title]') targeting SilverStripe\Forms\CompositeField::fieldByName() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
83
    }
84
85
    public function getLinkField()
86
    {
87
        $name = $this->name;
88
        return $this->fieldByName("{$name}[Link]");
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->fieldByName($name.'[Link]') targeting SilverStripe\Forms\CompositeField::fieldByName() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
89
    }
90
91
    public function getNewWindowField()
92
    {
93
        $name = $this->name;
94
        return $this->fieldByName("{$name}[NewWindow]");
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->fieldByName($name.'[NewWindow]') targeting SilverStripe\Forms\CompositeField::fieldByName() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
95
    }
96
97
    public function getExtraClassesField()
98
    {
99
        $name = $this->name;
100
        return $this->fieldByName("{$name}[ExtraClasses]");
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->fieldByName($name.'[ExtraClasses]') targeting SilverStripe\Forms\CompositeField::fieldByName() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
101
    }
102
}
103