|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2013-2019 Sergio Coderius! |
|
4
|
|
|
* @link https://coderius.biz.ua |
|
5
|
|
|
* @license This program is free software: the MIT License (MIT) |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace coderius\pell; |
|
9
|
|
|
|
|
10
|
|
|
use yii\base\Model; |
|
11
|
|
|
use yii\helpers\Html; |
|
12
|
|
|
use yii\base\Widget; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* InputWidget is the base class for Pell widget. |
|
16
|
|
|
* |
|
17
|
|
|
* Classes extending from this widget can be used in an [[yii\widgets\ActiveForm|ActiveForm]] |
|
18
|
|
|
* using the [[yii\widgets\ActiveField::widget()|widget()]] method, for example like this: |
|
19
|
|
|
* |
|
20
|
|
|
* ```php |
|
21
|
|
|
* <?= $form->field($model, 'from_date')->widget('WidgetClassName', [ |
|
22
|
|
|
* // configure additional widget properties here |
|
23
|
|
|
* ]) ?> |
|
24
|
|
|
* ``` |
|
25
|
|
|
* |
|
26
|
|
|
* @author Sergio Coderius <[email protected]> |
|
27
|
|
|
*/ |
|
28
|
|
|
class PellInputWidget extends Widget |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* @var Model the data model that this widget is associated with. |
|
32
|
|
|
*/ |
|
33
|
|
|
public $model; |
|
34
|
|
|
/** |
|
35
|
|
|
* @var string the model attribute that this widget is associated with. |
|
36
|
|
|
*/ |
|
37
|
|
|
public $attribute; |
|
38
|
|
|
/** |
|
39
|
|
|
* @var string the input name. This must be set if [[model]] and [[attribute]] are not set. |
|
40
|
|
|
*/ |
|
41
|
|
|
public $name; |
|
42
|
|
|
/** |
|
43
|
|
|
* @var string the input value. |
|
44
|
|
|
*/ |
|
45
|
|
|
public $value; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var array the HTML attributes for the widget container tag. |
|
49
|
|
|
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. |
|
50
|
|
|
*/ |
|
51
|
|
|
public $inputOptions = []; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Initializes the widget. |
|
55
|
|
|
* If you override this method, make sure you call the parent implementation first. |
|
56
|
|
|
*/ |
|
57
|
27 |
|
public function init() |
|
58
|
|
|
{ |
|
59
|
27 |
|
if ($this->hasModel() && !isset($this->inputOptions['id'])) { |
|
60
|
12 |
|
$this->inputOptions['id'] = Html::getInputId($this->model, $this->attribute); |
|
61
|
|
|
} |
|
62
|
27 |
|
parent::init(); |
|
63
|
27 |
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @return bool whether this widget is associated with a data model. |
|
67
|
|
|
*/ |
|
68
|
27 |
|
protected function hasModel() |
|
69
|
|
|
{ |
|
70
|
27 |
|
return $this->model instanceof Model && $this->attribute !== null; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|