How to set add-on's navtab permission based

Dadparvar

Well-known member
Hi,

My add-on has a navigation tab + child tabs.

I can set permission for usergroups to set if they can see child tabs or not.

But how to set Add-on's main tab in navbar permission based?

Regards
 
You can add the permission conditional before the $extraTabs array.

Can you please post here the code that you are using to add the tab?
 
I created tabs for my add-on using a route.
Code:
<?php

class Path_To_Route_Prefix_Index implements XenForo_Route_Interface
{
    public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
    {
        $action = $router->resolveActionWithIntegerParam($routePath, $request, 'template_id');
                $routeMatch = $router->getRouteMatch('Path_To_ControllerPublic_Index', $action, 'tabname', $routePath);
                return $routeMatch;
    }
}
 
I was talking about the code that adds the tab in the navigation menu, not the router.
 
I was talking about the code that adds the tab in the navigation menu, not the router.
Oosp!
the navigation.php file:
Code:
<?php

class Path_to_Listeners_Navigation
{
    public static function navtabs(array &$extraTabs, $selectedTabId)
    {
        $extraTabs['tabname'] = array(
            'title' => 'Name',
            'href' => 'name/',
            'selected' => ($selectedTabId == 'newsticker'),
            'linksTemplate' => 'my_temp_Navtabs',
        );
    }
}

and the template:
Code:
<ul class="secondaryContent blockLinksList">
    <li><a href="{xen:link pageofit/}">Title</a></li>
</ul>
 
PHP:
public static function navtabs(array &$extraTabs, $selectedTabId)
{
   if (XenForo_Visitor::getInstance()->hasPermission(permissionGroup', 'permissionName'))
   {
        $extraTabs['tabname'] = array(
            'title' => 'Name',
            'href' => 'name/',
            'selected' => ($selectedTabId == 'newsticker'),
            'linksTemplate' => 'my_temp_Navtabs',
        );
   }
}
 
PHP:
public static function navtabs(array &$extraTabs, $selectedTabId)
{
   if (XenForo_Visitor::getInstance()->hasPermission(permissionGroup', 'permissionName'))
   {
        $extraTabs['tabname'] = array(
            'title' => 'Name',
            'href' => 'name/',
            'selected' => ($selectedTabId == 'newsticker'),
            'linksTemplate' => 'my_temp_Navtabs',
        );
   }
}
Awesome.

Worked.

Thanks
 
You should be using the XF link builder instead of hard coding the URL like this:
PHP:
'href' => 'name/'
The correct way is:
PHP:
'href' => XenForo_Link::buildPublicLink('name')
(It takes the same arguments as the {xen:link} template function).

Your href won't work for people without friendly URLs enabled and if the route was ever changed with a route filter, that wouldn't work properly either.
 
Back
Top Bottom