• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

How to set add-on's navtab permission based

Dadparvar

Well-known member
#1
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
 

wang

Well-known member
#4
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?
 

Dadparvar

Well-known member
#5
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;
    }
}
 

Dadparvar

Well-known member
#7
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>
 

wang

Well-known member
#8
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',
        );
   }
}
 

Dadparvar

Well-known member
#9
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
 

Chris D

XenForo developer
Staff member
#10
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.