Total Complexity | 6 |
Total Lines | 48 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
14 | class Passfield extends InputWidget |
||
15 | { |
||
16 | /** |
||
17 | * @var \yii\widgets\ActiveForm |
||
18 | */ |
||
19 | public $form; |
||
20 | /** |
||
21 | * @var array Passfield options |
||
22 | */ |
||
23 | public $config = []; |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | public $label; |
||
29 | |||
30 | /** |
||
31 | * @inheritdoc |
||
32 | * @return $this|string |
||
33 | * @throws InvalidConfigException |
||
34 | */ |
||
35 | public function run() |
||
36 | { |
||
37 | $this->registerAssets(); |
||
38 | if ($this->hasModel()) { |
||
39 | if ($this->form == null) { |
||
40 | throw new InvalidConfigException(__CLASS__ . '.form property must be specified'); |
||
41 | } |
||
42 | if (empty($this->label)) { |
||
43 | return $this->form->field($this->model, $this->attribute)->passwordInput($this->options); |
||
44 | } |
||
45 | return $this->form |
||
46 | ->field($this->model, $this->attribute) |
||
47 | ->passwordInput($this->options) |
||
48 | ->label($this->label); |
||
49 | } else { |
||
50 | return Html::passwordInput($this->name, $this->value, $this->options); |
||
51 | } |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Register Assets |
||
56 | */ |
||
57 | public function registerAssets() |
||
62 | } |
||
63 | } |
||
64 |