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

Adding navigation tab that stays selected.

Discussion in 'XenForo Development Discussions' started by Epi, Dec 28, 2014.

  1. Epi

    Epi Member

    I'm trying to create a tab, for tinthe xentag but i can't keep it selected somehow. this is my code

    PHP:
    <?php
    class Tinhte_XenTag_navtab
    {
        public static function 
    listen(array &$extraTabs$selectedTabId)
        {
            
    $extraTabs['tags'] = array(
                
    'title' => new XenForo_Phrase('xentag_navbar_tab'),
                
    'href'   => XenForo_Link::buildPublicLink('full:tags'),
                
    'selected' => ($selectedTabId == 'tags'),
                
    'position'  =>  'middle'
              
            
    );
        }
    whenever i click on the tags tab, the selected tab always goes to 'forums'
    any help would be deeply appreciated
     
  2. NixFifty

    NixFifty Well-Known Member

    What does your 'tags' route look like? That's where you can specify which tab will be selected.

    Best example would be line 19 of /library/XenForo/Route/Prefix/Forums.php

    PHP:
    return $router->getRouteMatch('XenForo_ControllerPublic_Forum'$action'forums');
    The third parameter specifies the selected tab id (in your case, it'd be 'tabs').
     
    Epi and otaku like this.
  3. NixFifty

    NixFifty Well-Known Member

    Epi and otaku like this.
  4. Epi

    Epi Member

    Oh lol getting too complicated. well yeah i found this. got no idea how to add the route in it though.

    Do you have any good php book recommendations that help me out with these things :p

    in /Tinhte/XenTag/Route/Prefix/Tags.php

    PHP:
    public function match($routePathZend_Controller_Request_Http $requestXenForo_Router $router)
        {
            if (
    in_array($routePathself::$actions))
            {
                
    $action $routePath;
            }
            else
            {
                
    // switched to use `resolveActionWithIntegerOrStringParam instead of the old
                // thingy `resolveActionWithStringParam` because it is more robust, specifically
                // it can handle /tags/something while the old one couldn't
                
    $action $router->resolveActionWithIntegerOrStringParam($routePath$request'hi'Tinhte_XenTag_Constants::URI_PARAM_TAG_TEXT);

                if (
    preg_match('/^page-(\d+)$/'$action$matches))
                {
                    
    // supports matching /tags/text/page-n links
                    
    $request->setParam('page'$matches[1]);
                    
    $action 'view';
                }
            }

            return 
    $router->getRouteMatch('Tinhte_XenTag_ControllerPublic_Tag'$actionTinhte_XenTag_Option::get('majorSection'));
        }
     
  5. Epi

    Epi Member

    funny thing is that changing
    PHP:
     Tinhte_XenTag_Option::get('majorSection')
    to tags works though lol
     
  6. Epi

    Epi Member

    Is this the right way to do it?

    PHP:
    public function match($routePathZend_Controller_Request_Http $requestXenForo_Router $router)
        {
            if (
    in_array($routePathself::$actions))
            {
                
    $action $routePath;
            }
            else
            {
                
    // switched to use `resolveActionWithIntegerOrStringParam instead of the old
                // thingy `resolveActionWithStringParam` because it is more robust, specifically
                // it can handle /tags/something while the old one couldn't
                
    $action $router->resolveActionWithIntegerOrStringParam($routePath$request'hi'Tinhte_XenTag_Constants::URI_PARAM_TAG_TEXT);

                if (
    preg_match('/^page-(\d+)$/'$action$matches))
                {
                    
    // supports matching /tags/text/page-n links
                    
    $request->setParam('page'$matches[1]);
                    
    $action 'view';
                }
            }
            return 
    $router->getRouteMatch('Tinhte_XenTag_ControllerPublic_Tag'$action'tags'); <--- added this router before the other one
            
    return $router->getRouteMatch('Tinhte_XenTag_ControllerPublic_Tag'$actionTinhte_XenTag_Option::get('majorSection'));
                 
        }
     
  7. Epi

    Epi Member

    Okay i think I get it. 'majorSection' is the forum tab so if i just comment that out and replace it with the one above I guess it's the same, except that it now changes to tags. Thanks a lot for the help, at least now I know how routes work in xenforo
     

Share This Page