Completed
Push — master ( a16f95...ef3d2f )
by Nate
03:19
created

Email::settings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 9
cp 0
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://raw.githubusercontent.com/flipboxfactory/craft-link/master/LICENSE
6
 * @link       https://github.com/flipboxfactory/craft-link
7
 */
8
9
namespace flipbox\craft\link\types;
10
11
use flipbox\craft\link\Link;
12
13
/**
14
 * @author Flipbox Factory <[email protected]>
15
 * @since 1.1.0
16
 */
17
class Email extends AbstractType
18
{
19
    /**
20
     * The base template path to the field type templates
21
     */
22
    const BASE_TEMPLATE_PATH = AbstractType::BASE_TEMPLATE_PATH . '/email';
23
24
    /**
25
     * The settings template path
26
     */
27
    const SETTINGS_TEMPLATE_PATH = self::BASE_TEMPLATE_PATH . '/settings';
28
29
    /**
30
     * The input template path
31
     */
32
    const INPUT_TEMPLATE_PATH = self::BASE_TEMPLATE_PATH . '/input';
33
34
    /**
35
     * @var
36
     */
37
    public $email;
38
39
    /**
40
     * @var string|null The input’s placeholder text
41
     */
42
    public $placeholder;
43
44
    /**
45
     * @inheritdoc
46
     */
47
    public static function displayName(): string
48
    {
49
        return Link::t('Email');
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function getUrl(): string
56
    {
57
        return $this->email ? ('mailto:' . $this->email) :  '';
58
    }
59
60
    /**
61
     * @inheritdoc
62
     */
63
    public function settings(): array
64
    {
65
        return array_merge(
66
            parent::settings(),
67
            [
68
                'placeholder'
69
            ]
70
        );
71
    }
72
73
    /**
74
     * @inheritdoc
75
     */
76
    public function attributes()
77
    {
78
        return array_merge(
79
            parent::attributes(),
80
            [
81
                'email'
82
            ]
83
        );
84
    }
85
86
    /**
87
     * @inheritdoc
88
     */
89
    public function rules()
90
    {
91
        return array_merge(
92
            parent::rules(),
93
            [
94
                [
95
                    [
96
                        'email'
97
                    ],
98
                    'email',
99
                    'on' => [
100
                        self::SCENARIO_INPUT
101
                    ]
102
                ],
103
                [
104
                    [
105
                        'email'
106
                    ],
107
                    'required',
108
                    'on' => [
109
                        self::SCENARIO_INPUT
110
                    ]
111
                ],
112
                [
113
                    [
114
                        'email'
115
                    ],
116
                    'safe',
117
                    'on' => [
118
                        self::SCENARIO_DEFAULT
119
                    ]
120
                ]
121
            ]
122
        );
123
    }
124
}
125