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

Selected Tabs

Discussion in 'XenForo Development Discussions' started by Robust, Dec 4, 2014.

  1. Robust

    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.
     
  2. Jeremy

    Jeremy XenForo Moderator Staff Member

    The selected tab is defined by the RoutePrefix
     
  3. AndyB

    AndyB Well-Known Member

    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($routePathZend_Controller_Request_Http $requestXenForo_Router $router)
        {
            return 
    $router->getRouteMatch('Andy_Calendar_ControllerPublic_Calendar'$routePath'forums');
        }
    }
     
    CrispinP likes this.
  4. Robust

    Robust Well-Known Member

    @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.
     
  5. AndyB

    AndyB Well-Known Member

    Robust likes this.
  6. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    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($routePathZend_Controller_Request_Http $requestXenForo_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 likes this.
  7. Robust

    Robust Well-Known Member

    @Mr. Goodie2Shoes What about the Upgrades tab (basically links to account/upgrades)
     
  8. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    @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...
     
    Robust likes this.
  9. Robust

    Robust Well-Known Member

  10. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    @Robust you selected 'load_class_controller' but it should be 'load_class_route_prefix' for the help page ;)
     
  11. Robust

    Robust Well-Known Member

    Thank you so much :) Now I just gotta learn what every bit of that does for later use.
     
  12. Robust

    Robust Well-Known Member

    @Mr. Goodie2Shoes One last thing...

    Before:
    Screen Shot 2015-02-22 at 13.28.39.png
    After:
    Screen Shot 2015-02-22 at 13.28.54.png

    It shows Help twice in the lower navigation. Is that a problem?
     
  13. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    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>
    
    ;)
     

Share This Page