Skip to content

Commit

Permalink
add visible option to item
Browse files Browse the repository at this point in the history
  • Loading branch information
microinginer committed Sep 19, 2017
1 parent 34db50f commit 380079f
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/DropDownActionColumn.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<?php
/**
* Created by PhpStorm.
* User: inginer
* Date: 03.09.15
* Time: 17:55
*/

namespace microinginer\dropDownActionColumn;

Expand All @@ -13,9 +7,10 @@
use yii\grid\Column;
use yii\helpers\Html;


/**
* Class DropDownActionColumn
* @package app\components
* @package microinginer\dropDownActionColumn
*/
class DropDownActionColumn extends Column
{
Expand Down Expand Up @@ -58,7 +53,7 @@ class DropDownActionColumn extends Column
* This method is invoked at the end of the constructor after the object is initialized with the
* given configuration.
*/
public function init ()
public function init()
{
$this->defaultItems = !$this->items;
parent::init();
Expand All @@ -67,32 +62,41 @@ public function init ()
/**
* @inheritdoc
*/
protected function renderDataCellContent ($model, $key, $index)
protected function renderDataCellContent($model, $key, $index)
{
$result = '';

if ($this->defaultItems) {
$this->items = [
[
'label' => Yii::t('yii', 'Update'),
'url' => ['update']
'url' => ['update'],
'visible' => true,
],
[
'label' => Yii::t('yii', 'View'),
'url' => ['view']
'url' => ['view'],
'visible' => true,
],
[
'label' => Yii::t('yii', 'Delete'),
'url' => ['delete'],
'url' => ['delete'],
'linkOptions' => [
'data-method' => 'post'
],
'visible' => true,
],
];
}

foreach ($this->items as $key => $value) {
if (isset($value['visible']) && false === $value['visible']) {
unset($this->items[$key]);
}
}

$firstKey = current(array_keys($this->items));
$mainBtn = $this->items[ $firstKey ];
$mainBtn = $this->items[$firstKey];

$result .= Html::a($mainBtn['label'], array_merge($mainBtn['url'], [$model->primaryKey()[0] => $key]), array_merge(
['class' => 'btn btn-default btn-sm'],
Expand All @@ -103,8 +107,8 @@ protected function renderDataCellContent ($model, $key, $index)
$result .= Html::button(
Html::tag('span', '', ['class' => 'caret']) .
Html::tag('span', 'Toggle Dropdown', ['class' => 'sr-only']), [
'class' => 'btn btn-default btn-sm dropdown-toggle',
'data-toggle' => 'dropdown',
'class' => 'btn btn-default btn-sm dropdown-toggle',
'data-toggle' => 'dropdown',
'aria-haspopup' => 'true',
'aria-expanded' => 'false',
]
Expand All @@ -122,7 +126,7 @@ protected function renderDataCellContent ($model, $key, $index)
} else {
$isVisible = true;
}
if($isVisible){
if ($isVisible) {

if ($firstElement) {
$firstElement = false;
Expand Down

0 comments on commit 380079f

Please sign in to comment.