1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace app\modules\grid; |
4
|
|
|
|
5
|
|
|
use Yii; |
6
|
|
|
use yii\grid\ActionColumn as YiiActionColumn; |
7
|
|
|
use yii\helpers\Html; |
8
|
|
|
|
9
|
|
|
class ActionColumn extends YiiActionColumn |
10
|
|
|
{ |
11
|
|
|
public $headerOptions = ['width' => '110', 'class' => 'action-column']; |
12
|
|
|
|
13
|
|
|
protected function initDefaultButtons() |
14
|
|
|
{ |
15
|
|
View Code Duplication |
if (!isset($this->buttons['view'])) { |
|
|
|
|
16
|
|
|
$this->buttons['view'] = function ($url, $model, $key) { |
|
|
|
|
17
|
|
|
$options = array_merge([ |
18
|
|
|
'title' => Yii::t('yii', 'View'), |
19
|
|
|
'aria-label' => Yii::t('yii', 'View'), |
20
|
|
|
'data-pjax' => '0', |
21
|
|
|
'class' => 'btn btn-primary', |
22
|
|
|
], $this->buttonOptions); |
23
|
|
|
return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, $options); |
24
|
|
|
}; |
25
|
|
|
} |
26
|
|
View Code Duplication |
if (!isset($this->buttons['update'])) { |
|
|
|
|
27
|
|
|
$this->buttons['update'] = function ($url, $model, $key) { |
|
|
|
|
28
|
|
|
$options = array_merge([ |
29
|
|
|
'title' => Yii::t('yii', 'Update'), |
30
|
|
|
'aria-label' => Yii::t('yii', 'Update'), |
31
|
|
|
'data-pjax' => '0', |
32
|
|
|
'class' => 'btn btn-info', |
33
|
|
|
], $this->buttonOptions); |
34
|
|
|
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, $options); |
35
|
|
|
}; |
36
|
|
|
} |
37
|
|
|
if (!isset($this->buttons['delete'])) { |
38
|
|
|
$this->buttons['delete'] = function ($url, $model, $key) { |
|
|
|
|
39
|
|
|
$options = array_merge([ |
40
|
|
|
'title' => Yii::t('yii', 'Delete'), |
41
|
|
|
'aria-label' => Yii::t('yii', 'Delete'), |
42
|
|
|
'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'), |
43
|
|
|
'data-method' => 'post', |
44
|
|
|
'data-pjax' => '0', |
45
|
|
|
'class' => 'btn btn-danger', |
46
|
|
|
], $this->buttonOptions); |
47
|
|
|
return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, $options); |
48
|
|
|
}; |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.