|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the fangface/yii2-concord package |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view |
|
6
|
|
|
* the file LICENSE.md that was distributed with this source code. |
|
7
|
|
|
* |
|
8
|
|
|
* @package fangface/yii2-concord |
|
9
|
|
|
* @author Fangface <[email protected]> |
|
10
|
|
|
* @copyright Copyright (c) 2014 Fangface <[email protected]> |
|
11
|
|
|
* @license https://github.com/fangface/yii2-concord/blob/master/LICENSE.md MIT License |
|
12
|
|
|
* |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace fangface\widgets; |
|
16
|
|
|
|
|
17
|
|
|
use backend\assets\BootstrapSelectAsset; |
|
18
|
|
|
use fangface\widgets\InputWidget; |
|
19
|
|
|
use fangface\helpers\Html; |
|
20
|
|
|
use yii\helpers\ArrayHelper; |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Bootstrap Select Widget |
|
25
|
|
|
*/ |
|
26
|
|
|
class BootstrapSelect extends InputWidget |
|
27
|
|
|
{ |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var string the name of the jQuery plugin |
|
31
|
|
|
*/ |
|
32
|
|
|
public $pluginName = 'selectpicker'; |
|
33
|
|
|
/** |
|
34
|
|
|
* @var array default widget plugin options that user pluginOptions will be merged into |
|
35
|
|
|
*/ |
|
36
|
|
|
public $defaultPluginOptions = []; |
|
37
|
|
|
/** |
|
38
|
|
|
* @var array the HTML attributes for the input tag. |
|
39
|
|
|
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. |
|
40
|
|
|
*/ |
|
41
|
|
|
public $options = ['class' => 'form-control bs-select']; |
|
42
|
|
|
/** |
|
43
|
|
|
* @var array the items to appear in the drop down list |
|
44
|
|
|
*/ |
|
45
|
|
|
public $items = null; |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Renders the color picker widget |
|
50
|
|
|
*/ |
|
51
|
|
|
protected function renderWidget() |
|
52
|
|
|
{ |
|
53
|
|
|
if (isset($this->options['multiple']) && $this->options['multiple']) { |
|
54
|
|
|
$this->options['multiple'] = 'multiple'; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$this->prepareInput(); |
|
58
|
|
|
$this->registerAssets(); |
|
59
|
|
|
$this->prepareTemplate(); |
|
60
|
|
|
echo $this->renderTemplate(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Prepare the input |
|
65
|
|
|
* |
|
66
|
|
|
* @return string |
|
67
|
|
|
*/ |
|
68
|
|
|
protected function prepareInput() |
|
69
|
|
|
{ |
|
70
|
|
|
if ($this->hasModel()) { |
|
71
|
|
|
$this->sections['input'] = Html::activeDropDownList($this->model, $this->attribute, $this->items, $this->options); |
|
72
|
|
|
} else { |
|
73
|
|
|
$this->sections['input'] = Html::dropDownList($this->model, $this->attribute, $this->items, $this->options); |
|
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Registers the needed client assets |
|
80
|
|
|
* |
|
81
|
|
|
* @return void |
|
82
|
|
|
*/ |
|
83
|
|
|
public function registerAssets() |
|
84
|
|
|
{ |
|
85
|
|
|
if ($this->disabled) { |
|
86
|
|
|
return; |
|
87
|
|
|
} |
|
88
|
|
|
$view = $this->getView(); |
|
89
|
|
|
BootstrapSelectAsset::register($view); |
|
90
|
|
|
$element = "jQuery('#" . $this->options['id'] . "')"; |
|
91
|
|
|
$this->registerPlugin($this->pluginName, $element); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
} |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: