• This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

Add own Navigation Tabs

  • Thread starter Thread starter ragtek
  • Start date Start date
R

ragtek

Guest
This is a VERY BASIC tuturial how to add own Tabs.
See the quote for more infos;)
1. Create your classfile in the xenforo directory. I named it ragtekTab
PHP:
<?php
class XenForo_ragtekTab
{
  /**
    * add the "info" tab to the navbar
    * @param array $extraTabs
    * @param string $selectedTabId
    */
    public static function addNavbarTab(array &$extraTabs, $selectedTabId)
    {
        $extraTabs['info'] = array(
            'title' => new XenForo_Phrase('ragtek_infopage_navbartitle'),//phrase with the title for the link
            'href'  => XenForo_Link::buildPublicLink('info'),
            'linksTemplate' => 'ragtek_infopage_navbar',      //if you want to have a "sub menu" you can create a template for this
            'position'  =>  'middle'  //since beta 5, you can choose the position, where the link should be placed      possible positions: [SIZE=3][FONT=Arial]middle end home[/FONT][/SIZE]
        );
    }
}
You need a class with an static method.
The method have to parameters (as said in the documentation^^)

2. Create a Code Event Listener which "listens" to navigation tab
Called when preparing the tabs and links that are put in the main page navigation. You may use this event to add your own tabs.
Arguments:
  1. array &$extraTabs - you may push additional tabs onto this array. Each tab must be identified with a unique key (see $selectedTabId) and be an array with the following keys:
    • title - title for the main tab
    • href - link for the root of the tab
    • selected - boolean that determines whether the tab is currently selected
    • linksTemplate - the name of the template that contains the links that will be displayed in the second row. The outer HTML of this template should be a <ul class="secondaryContent blockLinksList">.
  2. string $selectedTabId - the name of the selected tab. Select your tab if this matches.
Then you have to set the class & method name
Execute Callback: xenforo_ragtekTab :: addNavbarTab

That's it.
Now there should be a new tab;)

EDIT:
A quick note:

If you use a phrase for the tab title, you SHOULD cache the phrase.
This will save you an global DB Query!
 
Just to add, if you are going to have an addon that is permission based, or you will turn off, you need to check for permissions / on/off state here as well so that the tab will reflect the state. ie:

Code:
            $options = XenForo_Application::get('options');

            if ($options->myaddonisTurnedOn)
            {

                      $extraTabs['my_tab'] = array(
                      'title' => $options->mytabName,
                      'selected' => ($selectedTabId == 'mytabName'),
                      'href' => XenForo_Link::buildPublicLink('myaddonLocation'),
                      'linksTemplate' => 'myAddon_links',
                      'linksTitle' => $myLinks
                      );
            }
 
We have realy to check if a add-in is active`?
That's not very nice and IMHO a huge design mistake.
Why is xenforo executing code from inactive add-ons? (can't belive it's happening^^)
 
We have realy to check if a add-in is active`?
That's not very nice and IMHO a huge design mistake.
Why is xenforo executing code from inactive add-ons? (can't belive it's happening^^)

XenForo does not do that. If the Add-on is inactive it is inactive.

My example is referring to if Admins have an Option to allow a specific group to access a new page, then only that group should see the tab (seems sensible to me). Or if the addon has an option to be turned on or off, the tab should be viewable or not, depending on the option. The example above demonstrates how to do that.

I changed the example to reflect turned on.
 
quote="Lawrence, post: 84258"]XenForo does not do that. If the Add-on is inactive it is inactive.
[/quote]
ok,i've misunderstood it^^
 
How do I add and remove tabs from the SECONDARY tablinks (not navtab) based on permissions?

I have the following navigation class:
Code:
<?php

class EWRporta_Listeners_Navigation
{
	public static function navtabs(array &$extraTabs, $selectedTabId)
	{
		$extraTabs['portal'] = array(
			'title' => 'Portal',
			'href' => XenForo_Link::buildPublicLink('full:portal'),
			'selected' => ($selectedTabId == 'portal'),
			'linksTemplate' => 'EWRporta_Navtabs',
		);
	}
}

The template 'EWRporta_Navtabs' controls the secondary tablinks.
Code:
<ul class="secondaryContent blockLinksList">
	<li><a href="{xen:link portal}">Portal</a></li>
</ul>

I want to be able to add tablinks based on permissions assuming I have the following permissions class:
Code:
<?php

class EWRporta_Model_Perms extends XenForo_Model
{
	public function canCreate(array $viewingUser = null)
	{
		$this->standardizeViewingUserReference($viewingUser);

		if (XenForo_Permission::hasPermission($viewingUser['permissions'], 'EWRporta', 'canCreate'))
		{
			return true;
		}

		return false;
	}
}
 
Do the check in the nav listener, and extend the array with something like: 'links', and populate it with an array of links. This is what I did for my XenStaff Add-on.

How do I add and remove tabs from the SECONDARY tablinks (not navtab) based on permissions?

I have the following navigation class:
Code:
<?php

class EWRporta_Listeners_Navigation
{
	public static function navtabs(array &$extraTabs, $selectedTabId)
	{
		$extraTabs['portal'] = array(
			'title' => 'Portal',
			'href' => XenForo_Link::buildPublicLink('full:portal'),
			'selected' => ($selectedTabId == 'portal'),
			'linksTemplate' => 'EWRporta_Navtabs',
'links' => $arrayoflinksbasedonPermissions
		);
	}
}
 
Can you self control in what order the links are added in the navbar? (I haven't had a chance to take a look at it yet)
Like for instance I would like to place my portal navbar link first in the order.
 
I think I found a better way to do this, if you just want to reefer a link to somewhere.

In the navigation template just add before the part that says "<!-- no selection -->" if you want to be the last link, else just do it before the one that you want.
In this example, I used my clan's radio link.

Code:
<!-- radio -->
		<li class="navTab radio PopupClosed"><a href="http://radio.superialbuilders.com" class="navLink">Radio</a></li>

You can see two examples in my clan forums:
http://forums.superialbuilders.com
 
How do I add and remove tabs from the SECONDARY tablinks (not navtab) based on permissions?

I have the following navigation class:
Code:
<?php

class EWRporta_Listeners_Navigation
{
	public static function navtabs(array &$extraTabs, $selectedTabId)
	{
		$extraTabs['portal'] = array(
			'title' => 'Portal',
			'href' => XenForo_Link::buildPublicLink('full:portal'),
			'selected' => ($selectedTabId == 'portal'),
			'linksTemplate' => 'EWRporta_Navtabs',
		);
	}
}

The template 'EWRporta_Navtabs' controls the secondary tablinks.
Code:
<ul class="secondaryContent blockLinksList">
	<li><a href="{xen:link portal}">Portal</a></li>
</ul>

I want to be able to add tablinks based on permissions assuming I have the following permissions class:
Code:
<?php

class EWRporta_Model_Perms extends XenForo_Model
{
	public function canCreate(array $viewingUser = null)
	{
		$this->standardizeViewingUserReference($viewingUser);

		if (XenForo_Permission::hasPermission($viewingUser['permissions'], 'EWRporta', 'canCreate'))
		{
			return true;
		}

		return false;
	}
}
Do you know how to set the the activ tab in the secondary navbar?
http://xenforo.com/community/threads/navbar-linkstemplate.7803/
 
No, IMHO it wouldn't be hard, BUT i don't want to code a "ugly" one, which is add-ing them on runtime.

I have some other ideas for my cms...
 
Top Bottom