XEditableColumn::renderDataCellContent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 0
cts 13
cp 0
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 2
1
<?php
2
/**
3
 * X-editable extension for Yii2
4
 *
5
 * @link      https://github.com/hiqdev/yii2-x-editable
6
 * @package   yii2-x-editable
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\xeditable\grid;
12
13
use hiqdev\higrid\DataColumn;
14
use hiqdev\xeditable\widgets\XEditable;
15
use Yii;
16
use yii\helpers\ArrayHelper;
17
18
/**
19
 * Class XEditableColumn.
20
 */
21
class XEditableColumn extends DataColumn
22
{
23
    /**
24
     * @var array options that will be passed to X-Editable widget
25
     */
26
    public $pluginOptions = [];
27
28
    /**
29
     * @var array
30
     */
31
    public $widgetOptions = [];
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    protected function renderDataCellContent($model, $key, $index)
37
    {
38
        return Yii::createObject(ArrayHelper::merge([
39
            'class' => XEditable::class,
40
            'model' => $model,
41
            'value' => $this->value,
42
            'attribute' => $this->attribute,
43
            'pluginOptions' => array_merge($this->pluginOptions, ['selector' => ".editable[data-pk={$key}][data-name={$this->attribute}]"]),
44
            'linkOptions' => [
45
                'style' => ['word-break' => 'break-all'],
46
            ],
47
        ], $this->widgetOptions))->run();
48
    }
49
}
50