{"action":"created","issue":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/9198","labels_url":"https://api.github.com/repos/yiisoft/yii2/issues/9198/labels{/name}","comments_url":"https://api.github.com/repos/yiisoft/yii2/issues/9198/comments","events_url":"https://api.github.com/repos/yiisoft/yii2/issues/9198/events","html_url":"https://github.com/yiisoft/yii2/issues/9198","id":96891231,"number":9198,"title":"[Feature] Visible of buttons in ActionColumn","user":{"login":"fornit1917","id":1011149,"avatar_url":"https://avatars.githubusercontent.com/u/1011149?v=3","gravatar_id":"","url":"https://api.github.com/users/fornit1917","html_url":"https://github.com/fornit1917","followers_url":"https://api.github.com/users/fornit1917/followers","following_url":"https://api.github.com/users/fornit1917/following{/other_user}","gists_url":"https://api.github.com/users/fornit1917/gists{/gist_id}","starred_url":"https://api.github.com/users/fornit1917/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fornit1917/subscriptions","organizations_url":"https://api.github.com/users/fornit1917/orgs","repos_url":"https://api.github.com/users/fornit1917/repos","events_url":"https://api.github.com/users/fornit1917/events{/privacy}","received_events_url":"https://api.github.com/users/fornit1917/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/yiisoft/yii2/labels/status:under%20discussion","name":"status:under discussion","color":"f7c6c7"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/yiisoft/yii2/milestones/9","html_url":"https://github.com/yiisoft/yii2/milestones/2.0.x","labels_url":"https://api.github.com/repos/yiisoft/yii2/milestones/9/labels","id":831720,"number":9,"title":"2.0.x","description":"","creator":{"login":"cebe","id":189796,"avatar_url":"https://avatars.githubusercontent.com/u/189796?v=3","gravatar_id":"","url":"https://api.github.com/users/cebe","html_url":"https://github.com/cebe","followers_url":"https://api.github.com/users/cebe/followers","following_url":"https://api.github.com/users/cebe/following{/other_user}","gists_url":"https://api.github.com/users/cebe/gists{/gist_id}","starred_url":"https://api.github.com/users/cebe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cebe/subscriptions","organizations_url":"https://api.github.com/users/cebe/orgs","repos_url":"https://api.github.com/users/cebe/repos","events_url":"https://api.github.com/users/cebe/events{/privacy}","received_events_url":"https://api.github.com/users/cebe/received_events","type":"User","site_admin":false},"open_issues":386,"closed_issues":2,"state":"open","created_at":"2014-10-19T13:49:45Z","updated_at":"2015-07-24T07:15:56Z","due_on":null,"closed_at":null},"comments":4,"created_at":"2015-07-23T19:45:17Z","updated_at":"2015-07-24T07:34:07Z","closed_at":null,"body":"Hi. My english is very bad, i'm sorry.\r\n\r\nI want to manage visible of buttons in ActionColumn (GridView). In current version we have the next solution: https://github.com/yiisoft/yii2/blob/5c79ab202cce74048957dce586d7ef2796908138/framework/grid/ActionColumn.php#L70\r\n\r\nBut i want set only boolean value for this. Example:\r\n\r\n```php\r\n'buttonsVisible' => [\r\n      'update' => \\Yii::$app->user->can('update'),\r\n      'delete' => function($model){\r\n            return \\Yii::$app->user->can('delete') && $model->status != Status::DELETED\r\n       },\r\n ]\r\n```\r\n\r\nThat is, I want to separate setting html-content of buttons in ActionColumn and setting visibility of this buttons.\r\nTo do this, we can add the parameter buttonsVisible to yii\\grid\\ActionColumn and modify of method renderDataCellContent:\r\n\r\n```php\r\nnamespace yii\\grid;\r\nclass ActionColumn \r\n{\r\n    public $buttonsVisible = [];\r\n\r\n\r\n    protected function renderDataCellContent($model, $key, $index)\r\n    {\r\n        return preg_replace_callback('/\\\\{([\\w\\-\\/]+)\\\\}/', function ($matches) use ($model, $key, $index) {\r\n            $name = $matches[1];\r\n\r\n            if (isset($this->buttonsVisible[$name])) {\r\n                $visible = is_callable($this->buttonsVisible[$name])\r\n                    ? call_user_func($this->buttonsVisible[$name], $model)\r\n                    : $this->buttonsVisible[$name];\r\n            } else {\r\n                $visible = true;\r\n            }\r\n\r\n            if ($visible && isset($this->buttons[$name])) {\r\n                $url = $this->createUrl($name, $model, $key, $index);\r\n                return call_user_func($this->buttons[$name], $url, $model, $key);\r\n            } else {\r\n                return '';\r\n            }\r\n        }, $this->template);\r\n    }   \r\n}\r\n```\r\n\r\nI can prepare a pull request.\r\nWhat do you think?"},"comment":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/comments/124390609","html_url":"https://github.com/yiisoft/yii2/issues/9198#issuecomment-124390609","issue_url":"https://api.github.com/repos/yiisoft/yii2/issues/9198","id":124390609,"user":{"login":"samdark","id":47294,"avatar_url":"https://avatars.githubusercontent.com/u/47294?v=3","gravatar_id":"","url":"https://api.github.com/users/samdark","html_url":"https://github.com/samdark","followers_url":"https://api.github.com/users/samdark/followers","following_url":"https://api.github.com/users/samdark/following{/other_user}","gists_url":"https://api.github.com/users/samdark/gists{/gist_id}","starred_url":"https://api.github.com/users/samdark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samdark/subscriptions","organizations_url":"https://api.github.com/users/samdark/orgs","repos_url":"https://api.github.com/users/samdark/repos","events_url":"https://api.github.com/users/samdark/events{/privacy}","received_events_url":"https://api.github.com/users/samdark/received_events","type":"User","site_admin":false},"created_at":"2015-07-24T07:34:07Z","updated_at":"2015-07-24T07:34:07Z","body":"OK. Overall sounds like a good addition."}}