Hide Menu Items and/or empty module
|
ATK Howto: Hide Menu Items and/or empty module
|
Issue
If you use the built-in security features for ATK you might have come accros the following scenario. If an user doesn't have rights on any of the nodes inside a module the module still appears in the main menu. This default behaviour is a little bit strange because when you click on a "empty" module you will only get the "back to Main menu" link. In this HowTo I will describe how you can hide a module from the main menu if there are no accessible nodes.
Solution
It is possible to set the conditions of a node-menuItem for appearing in the menu. This is also possible for the parent menuitem in a slightly different way.
class mod_bestellingen extends atkModule {
function getMenuItems() {
// securtiyConditions is a 1 dimensional array containing
// pairs of nodename and the right the user should have for it
// to appear in the menu.
$securityConditions = Array(
"bestellingen.orders","admin",
"bestellingen.items","admin"
);
// Parent menu item
$this->menuitem("bestellingen","","",$securityConditions);
// Add child items, only visible if parent menu item is visible
$this->menuitem(
"orders"
, dispatch_url("bestellingen.orders", "admin")
, "bestellingen"
, Array("bestellingen.orders","admin"));
$this->menuitem(
"items"
, dispatch_url("bestellingen.items", "admin")
, "bestellingen"
, Array("bestellingen.items","admin"));
}
This is just an example of the getMenuItems function. If you use this you should of course also have a getNodes function with the proper rights.