1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace thoulah\fontawesome\config; |
4
|
|
|
|
5
|
|
|
use yii\base\DynamicModel; |
6
|
|
|
use yii\helpers\ArrayHelper; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Icon Options. |
10
|
|
|
* |
11
|
|
|
* @return self Option values |
12
|
|
|
*/ |
13
|
|
|
class Options extends BaseConfig |
14
|
|
|
{ |
15
|
|
|
/** @var bool Whether or not to add calculated classes to custom files */ |
16
|
|
|
public $addClass = false; |
17
|
|
|
|
18
|
|
|
/** @var bool ActiveForm specific option. Whether to prepend or append the `input-group` |
19
|
|
|
* This will change both tag order and applied class. */ |
20
|
|
|
public $append = false; |
21
|
|
|
|
22
|
|
|
/** @var string Additional custom classes */ |
23
|
|
|
public $class; |
24
|
|
|
|
25
|
|
|
/** @var array Additional CSS attributes */ |
26
|
|
|
public $css; |
27
|
|
|
|
28
|
|
|
/** @var string Color of the icon */ |
29
|
|
|
public $fill; |
30
|
|
|
|
31
|
|
|
/** @var bool Whether or not to have fixed width icons */ |
32
|
|
|
public $fixedWidth; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string ActiveForm specific option. Set to `sm` for small or `lg` for large |
36
|
|
|
* Defaults to `md` or medium. |
37
|
|
|
* */ |
38
|
|
|
public $groupSize; |
39
|
|
|
|
40
|
|
|
/** @var int The height of the icon. This will dismiss the automatic height |
41
|
|
|
* and width classes. If `height` is given without `width`, the latter |
42
|
|
|
* will be calculated from the SVG size. */ |
43
|
|
|
public $height; |
44
|
|
|
|
45
|
|
|
/** @var string Id for the SVG tag */ |
46
|
|
|
public $id; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var string Name of the icon |
50
|
|
|
* @see https://fontawesome.com/icons |
51
|
|
|
*/ |
52
|
|
|
public $name; |
53
|
|
|
|
54
|
|
|
/** @var string CSS class name, requires custom CSS if changed */ |
55
|
|
|
public $prefix; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var string Style of the icon, must match `name` |
59
|
|
|
* @see https://fontawesome.com/icons |
60
|
|
|
*/ |
61
|
|
|
public $style; |
62
|
|
|
|
63
|
|
|
/** @var string Sets a title to the SVG output */ |
64
|
|
|
public $title; |
65
|
|
|
|
66
|
|
|
/** @var int The width of the icon. This will dismiss the automatic height |
67
|
|
|
* and width classes. If `height` is given without `width`, the latter |
68
|
|
|
* will be calculated from the SVG size. */ |
69
|
|
|
public $width; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Creates a new Options object. |
73
|
|
|
* |
74
|
|
|
* @param array $options Options |
75
|
|
|
*/ |
76
|
|
|
public function __construct(array $options = []) |
77
|
|
|
{ |
78
|
|
|
$allowedOptions = array_intersect_key($options, get_class_vars(__CLASS__)); |
79
|
|
|
parent::__construct($allowedOptions); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Validates the options. |
84
|
|
|
* |
85
|
|
|
* @param array|null $options Options |
86
|
|
|
* |
87
|
|
|
* @return string|null Validation errors |
88
|
|
|
*/ |
89
|
|
|
public function validate(): ?string |
90
|
|
|
{ |
91
|
|
|
$options = ArrayHelper::toArray($this); |
92
|
|
|
|
93
|
|
|
$model = DynamicModel::validateData( |
94
|
|
|
ArrayHelper::merge(get_class_vars(__CLASS__), $options), |
95
|
|
|
[ |
96
|
|
|
[['name'], 'required'], |
97
|
|
|
[['append', 'fixedWidth'], 'boolean'], |
98
|
|
|
[['class', 'fill', 'id', 'name', 'prefix', 'title'], 'string'], |
99
|
|
|
[['height', 'width'], 'integer', 'min' => 1], |
100
|
|
|
[['groupSize'], 'in', 'range' => self::VALID_GROUPSIZES], |
101
|
|
|
[['style'], 'in', 'range' => self::VALID_STYLES], |
102
|
|
|
] |
103
|
|
|
); |
104
|
|
|
|
105
|
|
|
return $this->errorSummary($model); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|