1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace dynamikaweb\grid; |
4
|
|
|
|
5
|
|
|
use kartik\icons\Icon; |
6
|
|
|
use yii\helpers\Html; |
7
|
|
|
use yii\helpers\Url; |
8
|
|
|
use yii\helpers\ArrayHelper; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
use Yii; |
12
|
|
|
|
13
|
|
|
class ActionColumn extends \yii\grid\ActionColumn |
14
|
|
|
{ |
15
|
|
|
public $headerOptions = ['class' => 'action-column', 'width' => '110px']; |
16
|
|
|
|
17
|
|
|
public $redirect = null; |
18
|
|
|
|
19
|
|
|
public $baseUrl = ""; |
20
|
|
|
|
21
|
|
|
public $pjax = null; |
22
|
|
|
|
23
|
|
|
public $messages = []; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
|
|
public function init() |
29
|
|
|
{ |
30
|
|
|
parent::init(); |
31
|
|
|
ActionColumnAsset::register(Yii::$app->view); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
protected function initDefaultButtons() |
35
|
|
|
{ |
36
|
|
|
$this->initDefaultButton('go', 'external-link-alt', ['target' => '_blank']); |
37
|
|
|
$this->initDefaultButton('view', 'eye'); |
38
|
|
|
$this->initDefaultButton('update', 'edit'); |
39
|
|
|
$this->initDefaultButton('delete', 'trash', [ |
40
|
|
|
'data-success' => Yii::t('yii', ArrayHelper::getValue($this->messages, 'success', 'Success!')), |
41
|
|
|
'data-delete' => Yii::t('yii', ArrayHelper::getValue($this->messages, 'delete', 'Are you sure you want to delete this item?')), |
42
|
|
|
'data-yes' => Yii::t('yii', ArrayHelper::getValue($this->messages, 'yes', 'Yes')), |
43
|
|
|
'data-no' => Yii::t('yii', ArrayHelper::getValue($this->messages, 'no', 'No')), |
44
|
|
|
'data-pjax' => $this->pjax |
45
|
|
|
]); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
protected function initDefaultButton($name, $iconName, $additionalOptions = []) |
49
|
|
|
{ |
50
|
|
|
if (!isset($this->buttons[$name]) && strpos($this->template, '{' . $name . '}') !== false) { |
51
|
|
|
$this->buttons[$name] = function ($url, $model, $key) use ($name, $iconName, $additionalOptions) { |
|
|
|
|
52
|
|
|
switch ($name) { |
53
|
|
|
case 'go': |
54
|
|
|
$title = Yii::t('yii', 'Redirect'); |
55
|
|
|
|
56
|
|
|
if ($this->redirect) { |
57
|
|
|
$url = Url::to(["{$this->redirect}", 'id' => $model->id, 'slug' => $model->getAttribute('slug')], true); |
58
|
|
|
} else { |
59
|
|
|
$this->controller = Yii::$app->controller->id; |
60
|
|
|
$url = Url::to(["{$this->controller}/view", 'id' => $model->id, 'slug' => $model->getAttribute('slug')], true); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$url = str_replace(Yii::$app->request->baseUrl, $this->baseUrl, $url); |
64
|
|
|
break; |
65
|
|
|
case 'view': |
66
|
|
|
$title = Yii::t('yii', 'View'); |
67
|
|
|
break; |
68
|
|
|
case 'update': |
69
|
|
|
$title = Yii::t('yii', 'Update'); |
70
|
|
|
break; |
71
|
|
|
case 'delete': |
72
|
|
|
$title = Yii::t('yii', 'Delete'); |
73
|
|
|
break; |
74
|
|
|
default: |
75
|
|
|
$title = ucfirst($name); |
76
|
|
|
} |
77
|
|
|
$options = array_merge([ |
78
|
|
|
'title' => $title, |
79
|
|
|
'aria-label' => $title, |
80
|
|
|
'data-pjax' => '0', |
81
|
|
|
], $additionalOptions, $this->buttonOptions); |
|
|
|
|
82
|
|
|
$icon = Icon::show($iconName, ['framework' => Icon::FAS]); |
83
|
|
|
return Html::a($icon, $url, $options); |
84
|
|
|
}; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.