|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GinoPane\AwesomeIconsList\FormWidgets; |
|
4
|
|
|
|
|
5
|
|
|
use Backend\Classes\FormWidgetBase; |
|
6
|
|
|
use GinoPane\AwesomeIconsList\Models\Settings; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Awesome Icons List Form Widget |
|
10
|
|
|
*/ |
|
11
|
|
|
class AwesomeIconsList extends FormWidgetBase |
|
12
|
|
|
{ |
|
13
|
|
|
const DEFAULT_ALIAS = 'awesomeiconslist'; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var bool Return unicode value for web font instead of valid CSS class |
|
17
|
|
|
*/ |
|
18
|
|
|
public $unicodeValue = false; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var string Placeholder when no icon is selected |
|
22
|
|
|
*/ |
|
23
|
|
|
public $placeholder = ''; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var string Add empty option to the option list |
|
27
|
|
|
*/ |
|
28
|
|
|
public $emptyOption = false; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @inheritDoc |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $defaultAlias = self::DEFAULT_ALIAS; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @inheritDoc |
|
37
|
|
|
*/ |
|
38
|
|
|
public function init() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->fillFromConfig([ |
|
41
|
|
|
'unicodeValue', |
|
42
|
|
|
'placeholder', |
|
43
|
|
|
'emptyOption' |
|
44
|
|
|
]); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @inheritDoc |
|
49
|
|
|
*/ |
|
50
|
|
|
public function render() |
|
|
|
|
|
|
51
|
|
|
{ |
|
52
|
|
|
$this->prepareVars(); |
|
53
|
|
|
|
|
54
|
|
|
return $this->makePartial('awesomeiconslist'); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Prepares the form widget view data |
|
59
|
|
|
*/ |
|
60
|
|
|
public function prepareVars() |
|
61
|
|
|
{ |
|
62
|
|
|
$this->vars['field'] = $this->formField; |
|
63
|
|
|
$this->vars['unicodeValue'] = $this->unicodeValue; |
|
64
|
|
|
$this->vars['placeholder'] = $this->placeholder; |
|
65
|
|
|
$this->vars['emptyOption'] = $this->emptyOption; |
|
66
|
|
|
|
|
67
|
|
|
$this->vars['value'] = $this->getLoadValue(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function loadAssets() |
|
71
|
|
|
{ |
|
72
|
|
|
/** @var Settings $settings */ |
|
73
|
|
|
$settings = Settings::instance(); |
|
74
|
|
|
|
|
75
|
|
|
$this->addCss( |
|
76
|
|
|
$settings->fontAwesomeLink(), |
|
77
|
|
|
$settings->fontAwesomeLinkAttributes() |
|
78
|
|
|
); |
|
79
|
|
|
|
|
80
|
|
|
$this->addCss("css/awesomeiconslist.css"); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
} |
|
84
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.