-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathActionColumn.php
61 lines (57 loc) · 1.96 KB
/
ActionColumn.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* This file is part of the yii2-uikit project.
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*
* @copyright yii2-uikit (c) 2018
* @author Eugene Zakirov (worstinme) <[email protected]>
*/
namespace worstinme\uikit;
use Yii;
use yii\helpers\Html;
class ActionColumn extends \yii\grid\ActionColumn
{
/**
* {@inheritdoc}
*/
protected function initDefaultButtons()
{
$this->initDefaultButton('view', 'link');
$this->initDefaultButton('update', 'pencil');
$this->initDefaultButton('delete', 'trash', [
'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'),
'data-method' => 'post',
]);
}
/**
* {@inheritdoc}
*/
protected function initDefaultButton($name, $iconName, $additionalOptions = [])
{
if (!isset($this->buttons[$name]) && strpos($this->template, '{' . $name . '}') !== false) {
$this->buttons[$name] = function ($url, $model, $key) use ($name, $iconName, $additionalOptions) {
switch ($name) {
case 'view':
$title = Yii::t('yii', 'View');
break;
case 'update':
$title = Yii::t('yii', 'Update');
break;
case 'delete':
$title = Yii::t('yii', 'Delete');
break;
default:
$title = ucfirst($name);
}
$options = array_merge([
'title' => $title,
'aria-label' => $title,
'data-pjax' => '0',
], $additionalOptions, $this->buttonOptions);
$icon = Html::tag('span', '', ['uk-icon'=>$iconName]);
return Html::a($icon, $url, $options);
};
}
}
}