CMSNicetiesLinkButton   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 16
c 2
b 0
f 0
dl 0
loc 36
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A Value() 0 11 2
1
<?php
2
3
namespace Sunnysideup\CMSNiceties\Forms;
4
5
use SilverStripe\Forms\ReadonlyField;
6
use SilverStripe\ORM\FieldType\DBField;
7
use SilverStripe\View\ViewableData;
8
9
// use SilverStripe\Forms\GridField\GridFieldArchiveAction;
10
11
class CMSNicetiesLinkButton extends ReadonlyField
12
{
13
    protected $link = '';
14
15
    protected $label = '';
16
17
    protected $targetBlank = false;
18
19
    /**
20
     * Creates a new field.
21
     *
22
     * @param string                   $name  the internal field name, passed to forms
23
     * @param null|string|ViewableData $label the human-readable field label
24
     * @param mixed                    $link  the value of the field
25
     */
26
    public function __construct($name, $label = null, $link = null, ?bool $targetBlank = false)
27
    {
28
        $title = '🚀';
29
        $this->link = $link;
30
        $this->label = $label;
31
        $this->targetBlank = $targetBlank;
32
33
        parent::__construct($name, $title, $link);
34
    }
35
36
    public function Value()
37
    {
38
        $target = '';
39
        if ($this->targetBlank) {
40
            $target = ' target="_blank" rel="noreferrer noopener"';
41
        }
42
43
        return DBField::create_field(
44
            'HTMLText',
45
            '<a href="' . $this->link . '" class="btn action btn-outline-primary" ' . $target . '>
46
                <span class="btn__title">' . $this->label . '</span>
47
            </a>'
48
        );
49
    }
50
}
51