MultipleMailCombo::getPluginOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 0
cts 22
cp 0
rs 9.536
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * Hosting Plugin for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-hosting
6
 * @package   hipanel-module-hosting
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\hosting\widgets\combo;
12
13
use yii\helpers\ArrayHelper;
14
use yii\web\JsExpression;
15
16
class MultipleMailCombo extends MailCombo
17
{
18
    public $multiple = true;
19
20
    /** {@inheritdoc} */
21
    public function getPluginOptions($options = [])
22
    {
23
        return parent::getPluginOptions(ArrayHelper::merge([
24
            'select2Options' => [
25
                'tags' => true,
26
                'tokenSeparators' => [', ', ' '],
27
                'createTag' => new JsExpression(/** @lang JavaScript */'
28
                    function (query) {
29
                        var term = query.term;
30
31
                        if (term.match(/^[0-9a-zA-Z\._+-]+@([0-9a-z][0-9a-z_-]*\.)+[0-9a-z][0-9a-z-]*$/i)) {
32
                            return {
33
                                id: term,
34
                                text: term,
35
                                tag: true
36
                            };
37
                        }
38
39
                        return null;
40
                    }
41
                '),
42
            ],
43
        ], $options));
44
    }
45
}
46