ClientSidePasswordField::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 4
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Sunnysideup\PasswordSaver\Form;
4
5
use SilverStripe\Forms\ReadonlyField;
6
use SilverStripe\ORM\FieldType\DBHTMLText;
7
8
class ClientSidePasswordField extends ReadonlyField
9
{
10
    protected $template = 'Sunnysideup/PasswordSaver/Form/ClientSidePasswordField';
11
    protected $ManagerLink;
12
13
    public function __construct($name, $title = null, $value = null, string $link = null)
14
    {
15
        parent::__construct($name, $title, $value);
16
        if ($link) {
17
            $this->ManagerLink = $link;
18
        }
19
    }
20
21
    public function ManagerLink()
22
    {
23
        return $this->ManagerLink;
24
    }
25
26
    public function setManagerLink(string $link)
27
    {
28
        $this->ManagerLink = $link;
29
    }
30
31
    public function Type()
32
    {
33
        return 'text password client-side-passsword';
34
    }
35
36
    public function Title()
37
    {
38
        return 'Password Key';
39
    }
40
41
    public function getDescription()
42
    {
43
        return implode(
44
            '<br />',
45
            array_filter(
46
                [
47
                    parent::getDescription(),
48
                    '<em>By separating username and password, you increase security.  Make sure to save the passwords somewhere securely, with the exact key listed here to ensure referential integrity.</em>',
49
                ]
50
            )
51
        );
52
    }
53
54
    /**
55
     * @return mixed|string
56
     */
57
    public function Value()
58
    {
59
        // Get raw value
60
        $value = $this->dataValue();
61
        $fontSize = '2em';
62
        if (!$value) {
63
            $value = 'Code not set yet - please save this record first';
64
            $fontSize = '1em';
65
        }
66
        return DBHTMLText::create_field(
67
            'HTMLText',
68
            '<pre style="margin-bottom:0; font-size: ' . $fontSize . ';">' . $value . '</pre>'
69
        );
70
71
    }
72
73
    public function isReadonly()
74
    {
75
        return false;
76
    }
77
78
    public function getTemplate()
79
    {
80
        return $this->template;
81
    }
82
}
83