{"action":"created","issue":{"url":"https://api.github.com/repos/yiisoft/yii2-bootstrap/issues/117","labels_url":"https://api.github.com/repos/yiisoft/yii2-bootstrap/issues/117/labels{/name}","comments_url":"https://api.github.com/repos/yiisoft/yii2-bootstrap/issues/117/comments","events_url":"https://api.github.com/repos/yiisoft/yii2-bootstrap/issues/117/events","html_url":"https://github.com/yiisoft/yii2-bootstrap/issues/117","id":130616552,"number":117,"title":"Automatically hide parent Nav section if all subitems are hidden","user":{"login":"arogachev","id":8326201,"avatar_url":"https://avatars.githubusercontent.com/u/8326201?v=3","gravatar_id":"","url":"https://api.github.com/users/arogachev","html_url":"https://github.com/arogachev","followers_url":"https://api.github.com/users/arogachev/followers","following_url":"https://api.github.com/users/arogachev/following{/other_user}","gists_url":"https://api.github.com/users/arogachev/gists{/gist_id}","starred_url":"https://api.github.com/users/arogachev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arogachev/subscriptions","organizations_url":"https://api.github.com/users/arogachev/orgs","repos_url":"https://api.github.com/users/arogachev/repos","events_url":"https://api.github.com/users/arogachev/events{/privacy}","received_events_url":"https://api.github.com/users/arogachev/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-02-02T08:53:01Z","updated_at":"2016-02-02T09:15:01Z","closed_at":null,"body":"Consider this example.\r\n\r\n```php\r\n$menuItems = [\r\n    [\r\n        'label' => 'Miscellaneous',\r\n        'items' => [\r\n            [\r\n                'label' => 'Users',\r\n                'url' => ['/users/index'],\r\n                'visible' => Yii::$app->user->can('users.manage'),\r\n            ],\r\n            [\r\n                'label' => 'Slides',\r\n                'url' => ['/slides/index'],\r\n                'visible' => Yii::$app->user->can('slides.manage'),\r\n            ],          \r\n            [\r\n                'label' => 'News,\r\n                'url' => ['/news/index'],\r\n                'visible' => Yii::$app->user->can('news.manage'),\r\n            ],\r\n        ],        \r\n    ],\r\n];\r\n\r\n echo Nav::widget([\r\n    'options' => ['class' => 'navbar-nav navbar-right'],\r\n    'items' => $menuItems,\r\n]);\r\n```\r\nIf the user doesn't have permissions to manage users, slides and news, `Miscellaneous` section will be still shown, but it doesn't make sense because it doesn't have a link (click triggers visibility of subitems).\r\n\r\nTo conditionally hide it we have to add something like this to parent section:\r\n\r\n```php\r\n'visible' => Yii::$app->user->can('users.manage') ||\r\n    Yii::$app->user->can('slides.manage') ||\r\n    Yii::$app->user->can('news.manage'),\r\n```\r\n\r\nThis is clean violation of DRY principle. Obviously we can have a helper method for checking that, but still we need to list permissions in both places, It's better to be done inside Nav widget itself.\r\n\r\nSo, if parent section have all subitems with `visible` property set and `visible` equals `false` in all subitems, we can just skip rendering of this whole section."},"comment":{"url":"https://api.github.com/repos/yiisoft/yii2-bootstrap/issues/comments/178465998","html_url":"https://github.com/yiisoft/yii2-bootstrap/issues/117#issuecomment-178465998","issue_url":"https://api.github.com/repos/yiisoft/yii2-bootstrap/issues/117","id":178465998,"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":"2016-02-02T09:15:01Z","updated_at":"2016-02-02T09:15:01Z","body":"Yep, that makes sense."}}