Completed
Push — master ( d77fc9...0ecf0a )
by Nate
05:31
created

AbstractType::displayName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/link/license
6
 * @link       https://www.flipboxfactory.com/software/link/
7
 */
8
9
namespace flipbox\link\types;
10
11
use Craft;
12
use craft\base\ElementInterface;
13
use flipbox\link\fields\Link;
14
use yii\base\Model;
15
16
/**
17
 * @author Flipbox Factory <[email protected]>
18
 * @since 1.0.0
19
 */
20
abstract class AbstractType extends Model implements TypeInterface
21
{
22
    use traits\Base;
23
24
    /**
25
     * @inheritdoc
26
     */
27
    public static function displayName(): string
28
    {
29
        $ref = new \ReflectionClass(static::class);
30
        return Craft::t('link', $ref->getShortName());
31
    }
32
33
    /**
34
     * @inheritdoc
35
     */
36
    public function settingsHtml(): string
37
    {
38
        return Craft::$app->getView()->renderTemplate(
39
            'link/_components/fieldtypes/Link/types/settings',
40
            [
41
                'type' => $this
42
            ]
43
        );
44
    }
45
46
    /**
47
     * @inheritdoc
48
     */
49
    public function inputHtml(Link $field, TypeInterface $value = null, ElementInterface $element = null): string
50
    {
51
        return '';
52
    }
53
54
    /**
55
     * @inheritdoc
56
     */
57
    public function attributes()
58
    {
59
        return array_merge(
60
            parent::attributes(),
61
            [
62
                'text'
63
            ]
64
        );
65
    }
66
67
    /**
68
     * @inheritdoc
69
     */
70
    public function attributeLabels()
71
    {
72
        return array_merge(
73
            parent::attributeLabels(),
74
            [
75
                'text' => Craft::t('link', 'Text')
76
            ]
77
        );
78
    }
79
80
    /**
81
     * @inheritdoc
82
     */
83
    public function rules()
84
    {
85
        return array_merge(
86
            parent::rules(),
87
            [
88
                [
89
                    [
90
                        'text'
91
                    ],
92
                    'safe',
93
                    'on' => [
94
                        Model::SCENARIO_DEFAULT
95
                    ]
96
                ]
97
            ]
98
        );
99
    }
100
}
101