-
Notifications
You must be signed in to change notification settings - Fork 3
/
Passfield.php
52 lines (46 loc) · 1.37 KB
/
Passfield.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/*
* This file is part of the Dektrium project.
*
* (c) Dektrium project <http://github.com/dektrium>
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
namespace dektrium\passfield;
use yii\base\InvalidConfigException;
use yii\helpers\Html;
use yii\widgets\InputWidget;
/**
* Pass*Field widget.
* @see http://antelle.github.io/passfield/
* @author Dmitry Erofeev <[email protected]>
*/
class Passfield extends InputWidget
{
/**
* @var \yii\widgets\ActiveForm
*/
public $form;
/**
* @var array Passfield options
*/
public $config = [];
/**
* @inheritdoc
*/
public function run()
{
Asset::register($this->view);
$config = empty($this->config) ? json_encode(['locale' => \Yii::$app->language]) : json_encode($this->config);
$this->view->registerJs(sprintf('$("#%s").passField(%s)', $this->options['id'], $config));
if ($this->hasModel()) {
if ($this->form == null) {
throw new InvalidConfigException(__CLASS__ . '.form property must be specified');
}
return $this->form->field($this->model, $this->attribute)->passwordInput($this->options);
} else {
return Html::passwordInput($this->name, $this->value, $this->options);
}
}
}