GroupActionColumn.php
2.6 KB
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
62
63
64
65
66
67
68
<?php
namespace artbox\catalog\widgets;
use yii\grid\ActionColumn;
use Yii;
use yii\helpers\Html;
/**
* Class GroupActionColumn
*
* @package artbox\catalog\widgets
*/
class GroupActionColumn extends ActionColumn
{
public $template = '{options} {seo} {view} {update} {delete}';
/**
* Initializes parent method and adds two artbox option group specific buttons
*/
protected function initDefaultButtons()
{
parent::initDefaultButtons();
$this->initArtboxButton('options', 'align-justify');
$this->initArtboxButton('seo', 'leaf');
}
/**
* Generate buttons for option list of current group
* and link to alias update
*
* @param $name
* @param $iconName
* @param array $additionalOptions
*/
protected function initArtboxButton($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 'options':
$title = Yii::t('yii', 'Options');
$link = str_replace('option-group', 'option', $url);
$link = str_replace('options', 'index', $link);
$link = str_replace('?id', '?group_id', $link);
break;
case 'seo':
$title = Yii::t('yii', 'Seo');
$link = [
'alias/view',
'id' => $model->lang->alias_id,
];
break;
default:
$title = ucfirst($name);
$link = $url;
}
$options = array_merge([
'title' => $title,
'aria-label' => $title,
'data-pjax' => '0',
], $additionalOptions, $this->buttonOptions);
$icon = Html::tag('span', '', ['class' => "glyphicon glyphicon-$iconName"]);
return Html::a($icon, $link, $options);
};
}
}
}