-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSelectWidget.php
53 lines (45 loc) · 1.29 KB
/
SelectWidget.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
53
<?php
namespace soluto\plugin;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\web\JsExpression;
class SelectWidget extends InputWidget
{
/**
* @var array $items the option data items. The array keys are option values, and the array values
* are the corresponding option labels.
*/
public $items = [];
/**
* @var array the initial selected item
*
* ```php
* 'selected' => [
* 'id' => $model->category_id,
* 'description' => ArrayHelper($model, 'category.description')
* ]
* ```
*/
public $selected = [];
/**
* @inheritdoc
*/
public function run()
{
$options = $this->options;
$id = $options['id'];
if ($this->hasModel()) {
echo Html::activeDropDownList($this->model, $this->attribute, $this->items, $options);
} else {
echo Html::dropDownList($this->name, $this->value, $this->items, $options);
}
if (isset($options['value'])) {
$value = $options['value'];
} else {
$value = $this->hasModel() ? Html::getAttributeValue($this->model, $this->attribute) : $this->value;
}
$this->pluginOptions['value'] = $value;
$this->registerPlugin($id);
}
}