Completed
Push — master ( 208ec8...41bf1b )
by Klochok
02:41
created

MultipleStaticCombo::renderInput()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * Combo widget for Yii2
5
 *
6
 * @link      https://github.com/hiqdev/yii2-combo
7
 * @package   yii2-combo
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hiqdev\combo;
13
14
use yii\helpers\Html;
15
16
/**
17
 * Class can be used for Combo instances, based on static data that should be submitted as array.
18
 * This implementation of [[Combo]] renders [[Html::activeDropDownList()]] instead of hidden input
19
 * and allows browser to submit input as array.
20
 *
21
 * Usage example:
22
 *
23
 * ```php
24
 *  echo $form->field($model, 'login_in')->widget(MultipleStaticCombo::class, [
25
 *      'hasId' => true,
26
 *      'data' => [
27
 *          'persons' => ['silverfire' => 'Dmitry Naumenko', 'sol' => 'Andrii Vasyliev'],
28
 *          'bots' => ['r2d2' => 'Artoo-Detoo']
29
 *      ],
30
 *      'inputOptions' => [
31
 *          'groups' => ['persons' => 'Humans', 'bots' => 'Robots'],
32
 *          'multiple' => true
33
 *      ]
34
 *  ])
35
 * ```
36
 *
37
 * @property mixed data
38
 */
39
class MultipleStaticCombo extends Combo
40
{
41
    public $name = 'default';
42
43
    public $type = 'default';
44
45
    /**
46
     * @var array Data to be
47
     */
48
    public $data;
49
50
    public function getPluginOptions($options = [])
51
    {
52
        $options = parent::getPluginOptions();
53
        unset($options['select2Options']['ajax']);
54
55
        return $options;
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    protected function renderInput()
62
    {
63
        return Html::activeDropDownList($this->model, $this->attribute, $this->data, $this->inputOptions);
64
    }
65
}
66