Selected Tabs

Robust

Well-known member
Wondering how to do this

PHP:
    /**
     * Adds a Help tab to the navigation
     * @param array $extraTabs
     * @param string $selectedTabId
     */
    public static function helpTab(array &$extraTabs, $selectedTabId)
    {
        $extraTabs['help'] = array(
            'title' => 'Help',
            'href'  => XenForo_Link::buildPublicLink('help'),
            'linksTemplate' => 'helptab_links',
            'selected' => ($selectedTabId == 'help'),
            'position'  =>  'end'
        );
    }

    /**
     * Adds a Upgrade tab to the navigation
     * @param array $extraTabs
     * @param string $selectedTabId
     */
    public static function upgradeTab(array &$extraTabs, $selectedTabId)
    {
        $extraTabs['upgrade'] = array(
            'title' => 'Upgrade',
            'href' => XenForo_Link::buildPublicLink('account/upgrades'),
            'position' => 'middle'
        );
    }

Thing is, without the selected option the tab isn't shown as selected. But with it, it isn't either. I'm assuming the $selectedTabId isn't 'help'? I've tried changing title to $selectedTabId just to debug and see what it is, but it ends up blank (empty).

Am I doing something wrong?

My code event listener is simply a navigation_tabs event one, two of them, one for helpTab and one for upgradeTab.
 
Here's an example where I have selected 'forums' tab to be selected.

PHP:
<?php

class Andy_Calendar_Route_Prefix_Calendar implements XenForo_Route_Interface
{
	public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
	{
		return $router->getRouteMatch('Andy_Calendar_ControllerPublic_Calendar', $routePath, 'forums');
	}
}
 
@AndyB Not fully sure how you'd use that function though - I have no clue on XenForo's route path(s). Plus I don't exactly have a controller. This plugin just adds tabs to existing pages in XenForo's system.
 
I am guessing that the 'Help' tab is associated with XenForo's help page?
Looking into the prefix class, they haven't set any '$majorSection' for the 'help' route prefix...

the code you provided for the tab is okay, so what you have to do is either directly edit the file /library/XenForo/Route/Prefix/Help.php and change line 14
PHP:
return $router->getRouteMatch('XenForo_ControllerPublic_Help', 'index');
to
PHP:
return $router->getRouteMatch('XenForo_ControllerPublic_Help', 'index', 'help');

or if you don't want to get your hands dirty create a proxy class for 'XenForo_Route_Prefix_Help' and add this method:
PHP:
  public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
   {
     $return = parent::match($routePath, $request, $router);

     if ($return instanceof XenForo_RouteMatch)
     {
       $return->setSections('help');
     }

     return $return;
   }

if its a custom add-on by you, the first method will go...
Hope it helps :)
 
@Robust
Suppose you have added an extra tab for the upgrades page like this:
PHP:
public static function addAccountUpgradeTab(array &$extraTabs, $selectedTabId)
{
    $extraTabs['accountUpgrades'] = array(
        'title' => 'Upgrades',
        'href' => XenForo_Link::buildPublicLink('full:account/upgrades')
    );
}

you'll have to create a proxy class for 'XenForo_ControllerPublic_Account' and add the following method:
PHP:
public function actionUpgrades()
{
    $this->_routeMatch->setSections('accountUpgrades');
    return parent::actionUpgrades();
}

So when the visitor goes to account/upgrades the newly created tab will be marked as selected ;)
Disclaimer: I just wrote the code here... do a double check as there might be any typo or silly mistakes...
 
yeah... that's bound to happen as the first "Help" in the breadcrumbs gets added from the navigation tab... what you can do is edit the template 'help_page', change:
Code:
<xen:navigation>
   <xen:breadcrumb href="{xen:link help}">{xen:phrase help}</xen:breadcrumb>
</xen:navigation>

to:
Code:
<xen:comment>
<xen:navigation>
   <xen:breadcrumb href="{xen:link help}">{xen:phrase help}</xen:breadcrumb>
</xen:navigation>
</xen:comment>

;)
 
Back
Top Bottom