Tbauthmenu: Access Checks For Your Menus

Hi all,

I whipped up a quick extension to the TbMenu/CMenu class that allows showing/hiding menu items using RBAC. There are a few extensions that do something similar, but they didn’t offer the control I needed and/or overrode my settings with odd defaults.

Parameters / Features:

  • authCheckAll - Whether to check every menu item, even if its authItem is not specified

  • authCheckNestedItems - Whether to check sub-items. (Ie $item['items])

  • authItem - Name of the auth item to check

  • authParams - Array of parameters to pass to checkAccess

  • authUser - ID of the user to check access for. Defaults to current user.

  • authResult - The expected return value of checkAccess. If something else is returned, the item and its children won’t be displayed

Parameters are checked at both the menu and item levels, with item-level parameters taking precedence.

Hope it helps!

  • Dan



In my opinion, it is more simple to set "visible" attribute of menu item, using CMenu.

I did this originally and ended up with cluttered code. YMMV. This also frees up the visible attribute for other logic. (Which could be done your way as well, but with a cost to readability.)